Documentation
¶
Index ¶
- func NewBuilder(table string, columns []string, dialect *info.Dialect, identity string, ...) (io.Builder, error)
- func ShowSQL(b bool)
- type Builder
- type Insertable
- type Service
- func (s *Service) Exec(ctx context.Context, any interface{}, options ...option.Option) (int64, int64, error)
- func (s *Service) NewSession(ctx context.Context, record interface{}, db *sql.DB, batchSize int) (*session, error)
- func (s *Service) NextSequence(ctx context.Context, any interface{}, recordCount int, ...) (*sink.Sequence, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder represent insert DML builder
type Insertable ¶ added in v0.5.4
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)
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.