insert

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2023 License: Apache-2.0 Imports: 16 Imported by: 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBuilder

func NewBuilder(table string, columns []string, dialect *info.Dialect, identity string, batchSize int) (io.Builder, error)

NewBuilder return insert builder

func ShowSQL added in v0.5.4

func ShowSQL(b bool)

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder represent insert DML builder

func (*Builder) Build

func (b *Builder) Build(record interface{}, options ...option.Option) string

Build builds insert statement

type Insertable added in v0.5.4

type Insertable interface {
	OnInsert(ctx context.Context) error
}

Insertable interface to be called on inserting data

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service represents generic db writer

func New

func New(ctx context.Context, db *sql.DB, tableName string, options ...option.Option) (*Service, error)

New creates an inserter service

func (*Service) Exec

func (s *Service) Exec(ctx context.Context, any interface{}, options ...option.Option) (int64, int64, error)

Exec runs insertService SQL

Example
package main

import (
	"context"
	"database/sql"
	"fmt"
	"github.com/viant/sqlx/io/insert"
	"github.com/viant/sqlx/option"
	"log"

	_ "github.com/viant/sqlx/metadata/product/mysql"
)

func main() {
	type Foo struct {
		ID   int
		Name string
	}
	dsn := ""
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		log.Fatalln(err)
	}

	insert, err := insert.New(context.TODO(), db, "mytable", option.BatchSize(1024))
	if err != nil {
		log.Fatalln(err)
	}
	var records []*Foo
	//records = getAppRecords()

	affected, lastID, err := insert.Exec(context.TODO(), records)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("affected: %v, last ID: %v\n", affected, lastID)
}
Output:

func (*Service) NewSession added in v0.1.1

func (s *Service) NewSession(ctx context.Context, record interface{}, db *sql.DB, batchSize int) (*session, error)

NewSession creates a new session

func (*Service) NextSequence added in v0.1.1

func (s *Service) NextSequence(ctx context.Context, any interface{}, recordCount int, options ...option.Option) (*sink.Sequence, error)

NextSequence resets next updateSequence

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL