gsorm

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: MIT Imports: 23 Imported by: 0

README

gsorm

Go Reference Go Report Card codecov

This is new Simple and SQL-like ORM framework written in Go language. gsorm lets you implement database operation easily and intuitively.

Major features of gsorm are as follows:

  • SQL-like implementation
  • Provide the gsorm's own mock
  • Mapping into struct, map, variable or their slice with high performance
  • Smart database migration using field tags of Go structure

You can see the usage in Quick Start or Documents

Benchmark

I measured the benchmark of the mapping query results with MySQL Employees Dataset which has about 300000 rows. Also I compared the average of 10 trials to other ORM libraries.

As a result, gsorm is faster than other libraries when mapping the multi rows.

The result are as follows:

ORM (ns/op)
standard 0.40952
gorm >= 200 ms/op
sqlx 0.49695
gorp 0.56168
gsorm 0.38252

If you want to run the benchmark on your machine, follow the steps below.

git clone git@github.com:champon1020/employees_database.git

cd employees_database

docker-compose up -d

cd /path/to/gsorm/benchmark

go test -bench . -benchmem -count 10

Benchmark codes are written under benchmark directory.

Installation

go get github.com/champon1020/gsorm

Features

SQL-Like Implementation

You can implement the database query intuitaively like writing SQL.

err := gsorm.Select(db, "emp_no", "first_name").From("employees").
    Where("emp_no > ?", 1002).
    Query(&model)
// SELECT emp_no, first_name FROM employees WHERE emp_no > 1002;

err := gsorm.Insert(db, "employees", "emp_no", "first_name").
    Values(1001, "Taro").
    Values(1002, "Jiro").
    Exec()
// INSERT INTO employees (emp_no, first_name) VALUES (1001, 'Taro'), (1002, 'Jiro');
Flexible Implementation

gsorm provides RawStmt and RawClause methods.

Using them, it is possible to implement the database query more flexible.

err := gsorm.Select(db).
    RawClause("INTO new_employees").
    From("employees").
    Where("emp_no > ?", 1002).
    Query(interface{}{})
// SELECT * INTO new_employees FROM employees WHERE emp_no > 1002;

err := gsorm.AlterTable(db, "employees").
    RawClause("MODIFY COLUMN emp_no INT(24)").NotNull().
    Migrate()
// ALTER TABLE employees MODIFY COLUMN emp_no INT(24) NOT NULL;

err := gsorm.RawStmt(db, "REPLACE INTO employees VALUES (?, ?)", 1003, "Saburo").Exec()
// REPLACE INTO employees VALUES (1003, 'Saburo');
Test with Mock

gsorm provides own Mock structure.

You can implement testing code with mock easily.

type Employee struct {
    EmpNo     int
    Firstname string
}

func TestWithMock(t *testing.T) {
    mock := gsorm.OpenMock()
    mock.Expect(gsorm.Insert(nil, "employees", "emp_no", "first_name").
        Values(1001, "Taro").
        Values(1002, "Jiro"))
    mock.ExpectWithReturn(gsorm.Select(nil, "emp_no", "first_name").From("employees"), []Employee{
        {ID: 1001, FirstName: "Taro"},
        {ID: 1002, FirstName: "Jiro"},
    })

    actualProcess := func(db gsorm.DB) error {
        model := []Employee{}

        if err := gsorm.Insert(nil, "employees", "emp_no", "first_name").
            Values(1001, "Taro").
            Values(1002, "Jiro").Exec(); err != nil {
            return err
        }

        if err := gsorm.Select(nil, "emp_no", "first_name").From("employees").Query(&model); err != nil {
            return err
        }

        return nil
    }

    if err := actualProcess(mock); err != nil {
        t.Error(err)
    }

    // Check if all expected statements was executed.
    if err := mock.Complete(); err != nil {
        t.Error(err)
    }
}
Smart Migration

Implementation of database migration tends to be complicated and high cost.

Using gsorm, it is possible to map the Go structure into SQL.

You can determine the properties of database columns using the field tag of the Go structure.

type Employee struct {
	EmpNo     int       `gsorm:"emp_no,pk=PK_emp_no,notnull=t"`
	Name      string    `gsorm:"first_name,typ=VARCHAR(14),notnull=t"`
	BirthDate time.Time `gsorm:"notnull=t"`
}

err := gsorm.CreateTable(db, "employees").Model(&Employee{}).Migrate()
	// CREATE TABLE employees (
	//      emp_no      INT         NOT NULL,
	//      first_name  VARCHAR(14) NOT NULL,
	//      birth_date  DATETIME    NOT NULL,
	//      CONSTRAINT PK_emp_no PRIMARY KEY (emp_no)
	// );

Quick Start

package main

import (
	"log"
	"time"

	"github.com/champon1020/gsorm"
	_ "github.com/go-sql-driver/mysql"
)

type Employee struct {
	EmpNo     int       `gsorm:"emp_no,pk=PK_emp_no,notnull=t"`
	Name      string    `gsorm:"first_name,typ=VARCHAR(14),notnull=t"`
	BirthDate time.Time `gsorm:"notnull=t"`
}

func main() {
	db, err := gsorm.Open("mysql", "root:toor@tcp(localhost:3306)/employees?parseTime=true")
	if err != nil {
		log.Fatal(err)
	}

	e := Employee{}

	// CREATE TABLE employees (
	//      emp_no      INT         NOT NULL,
	//      first_name  VARCHAR(14) NOT NULL,
	//      birth_date  DATETIME    NOT NULL,
	//      CONSTRAINT PK_emp_no PRIMARY KEY (emp_no)
	// );
	err = gsorm.CreateTable(db, "employees").Model(&e).Migrate()
	if err != nil {
		log.Fatal(err)
	}

	e = Employee{EmpNo: 1001, Name: "Taro", BirthDate: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)}

	// INSERT INTO employees VALUES (1001, 'Taro', '2006-01-02 15:04:05');
	err = gsorm.Insert(db, "employees").Model(&e).Exec()
	if err != nil {
		log.Fatal(err)
	}

	// INSERT INTO employees
	//      VALUES (1002, 'Jiro', '2007-01-02 15:04:05'), (1003, 'Saburo', '2006-01-02 15:04:05')
	err = gsorm.Insert(db, "employees").
		Values(1002, "Jiro", time.Date(2007, time.January, 2, 15, 4, 5, 0, time.UTC)).
		Values(1003, "Saburo", time.Date(2008, time.January, 2, 15, 4, 5, 0, time.UTC)).
		Exec()
	if err != nil {
		log.Fatal(err)
	}

	es := []Employee{}

	// SELECT first_name FROM employees WHERE id >= 1001;
	err = gsorm.Select(db, "first_name").From("employees").Query(&es)
	if err != nil {
		log.Fatal(err)
	}

	// UPDATE employees SET first_name = 'Kotaro' WHERE emp_no = 1001;
	err = gsorm.Update(db, "employees").Set("first_name", "Kotaro").Where("emp_no = ?", 1001).Exec()
	if err != nil {
		log.Fatal(err)
	}

	// DELETE FROM employees WHERE first_name = 'Kotaro';
	err = gsorm.Delete(db).From("employees").Where("first_name = ?", "Kotaro").Exec()
	if err != nil {
		log.Fatal(err)
	}

	// DROP TABLE employees;
	err = gsorm.DropTable(db, "employees").Migrate()
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Int         = reflect.TypeOf(int(0))
	Int8        = reflect.TypeOf(int8(0))
	Int16       = reflect.TypeOf(int16(0))
	Int32       = reflect.TypeOf(int32(0))
	Int64       = reflect.TypeOf(int64(0))
	Uint8       = reflect.TypeOf(uint8(0))
	Uint16      = reflect.TypeOf(uint16(0))
	Uint32      = reflect.TypeOf(uint32(0))
	Uint64      = reflect.TypeOf(uint64(0))
	Float32     = reflect.TypeOf(float32(0))
	Float64     = reflect.TypeOf(float64(0))
	Bool        = reflect.TypeOf(false)
	String      = reflect.TypeOf("")
	NullInt32   = reflect.TypeOf(sql.NullInt32{})
	NullInt64   = reflect.TypeOf(sql.NullInt64{})
	NullFloat64 = reflect.TypeOf(sql.NullFloat64{})
	NullBool    = reflect.TypeOf(sql.NullBool{})
	NullString  = reflect.TypeOf(sql.NullString{})
	NullTime    = reflect.TypeOf(sql.NullTime{})
	RawBytes    = reflect.TypeOf(sql.RawBytes{})
)

Types.

Functions

func AlterTable

func AlterTable(conn conn, table string) ialtertable.Stmt

AlterTable calls ALTER TABLE command.

func Avg

func Avg(conn conn, columns ...string) iselect.Stmt

Avg calls AVG function.

func Count

func Count(conn conn, columns ...string) iselect.Stmt

Count calls COUNT function.

func CreateDB

func CreateDB(conn conn, dbName string) icreatedb.Stmt

CreateDB calls CREATE DATABASE command.

func CreateIndex

func CreateIndex(conn conn, idx string) icreateindex.Stmt

CreateIndex calls CREATE INDEX command.

func CreateTable

func CreateTable(conn conn, table string) icreatetable.Stmt

CreateTable calls CREATE TABLE command.

func Delete

func Delete(conn conn) idelete.Stmt

Delete calls DELETE command.

func DropDB

func DropDB(conn conn, dbName string) idropdb.Stmt

DropDB calls DROP DATABASE command.

func DropTable

func DropTable(conn conn, table string) idroptable.Stmt

DropTable calls DROP TABLE command.

func Insert

func Insert(conn conn, table string, columns ...string) iinsert.Stmt

Insert calls INSERT command.

func Max

func Max(conn conn, columns ...string) iselect.Stmt

Max calls MAX function.

func Min

func Min(conn conn, columns ...string) iselect.Stmt

Min calls MIN function.

func RawStmt

func RawStmt(conn conn, raw string, values ...interface{}) iraw.Stmt

RawStmt calls raw string statement.

func Select

func Select(conn conn, columns ...string) iselect.Stmt

Select calls SELECT command.

func Sum

func Sum(conn conn, columns ...string) iselect.Stmt

Sum calls SUM function.

func Update

func Update(conn conn, table string) iupdate.Stmt

Update calls UPDATE command.

Types

type AlterTableStmt

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

AlterTableStmt is ALTER TABLE statement.

func (*AlterTableStmt) AddColumn

func (s *AlterTableStmt) AddColumn(column, typ string) ialtertable.AddColumn

AddColumn calls ADD COLUMN clause.

func (*AlterTableStmt) AddCons

func (s *AlterTableStmt) AddCons(key string) ialtertable.AddCons

AddCons calls ADD CONSTRAINT clause.

func (*AlterTableStmt) Default

func (s *AlterTableStmt) Default(value interface{}) ialtertable.Default

Default calls DEFAULT option.

func (*AlterTableStmt) DropColumn

func (s *AlterTableStmt) DropColumn(column string) ialtertable.DropColumn

DropColumn calls DROP COLUMN clause.

func (*AlterTableStmt) Foreign

func (s *AlterTableStmt) Foreign(columns ...string) ialtertable.Foreign

Foreign calls FOREIGN KEY keyword.

func (*AlterTableStmt) Migrate

func (s *AlterTableStmt) Migrate() error

Migrate executes database migration.

func (*AlterTableStmt) NotNull

func (s *AlterTableStmt) NotNull() ialtertable.NotNull

NotNull calls NOT NULL option.

func (*AlterTableStmt) Primary

func (s *AlterTableStmt) Primary(columns ...string) ialtertable.Primary

Primary calls PRIMARY KEY keyword.

func (*AlterTableStmt) RawClause

func (s *AlterTableStmt) RawClause(raw string, values ...interface{}) ialtertable.RawClause

RawClause calls the raw string clause.

func (*AlterTableStmt) Ref

func (s *AlterTableStmt) Ref(table string, columns ...string) ialtertable.Ref

Ref calls REFERENCES keyword.

func (*AlterTableStmt) Rename

func (s *AlterTableStmt) Rename(table string) ialtertable.Rename

Rename calls RENAME TO clause.

func (*AlterTableStmt) RenameColumn

func (s *AlterTableStmt) RenameColumn(column, dest string) ialtertable.RenameColumn

RenameColumn calls RENAME COLUMN clause.

func (*AlterTableStmt) SQL

func (s *AlterTableStmt) SQL() string

SQL returns the built SQL string.

func (*AlterTableStmt) Unique

func (s *AlterTableStmt) Unique(columns ...string) ialtertable.Unique

Unique calls UNIQUE keyword.

type CreateDBStmt

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

CreateDBStmt is CREATE DATABASE statement.

func (*CreateDBStmt) Migrate

func (s *CreateDBStmt) Migrate() error

Migrate executes database migration.

func (*CreateDBStmt) RawClause

func (s *CreateDBStmt) RawClause(raw string, values ...interface{}) icreatedb.RawClause

RawClause calls the raw string clause.

func (*CreateDBStmt) SQL

func (s *CreateDBStmt) SQL() string

SQL returns the built SQL string.

type CreateIndexStmt

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

CreateIndexStmt is CREATE INDEX statement.

func (*CreateIndexStmt) Migrate

func (s *CreateIndexStmt) Migrate() error

Migrate executes database migration.

func (*CreateIndexStmt) On

func (s *CreateIndexStmt) On(table string, columns ...string) icreateindex.On

On calls ON clause.

func (*CreateIndexStmt) RawClause

func (s *CreateIndexStmt) RawClause(raw string, values ...interface{}) icreateindex.RawClause

RawClause calls the raw string clause.

func (*CreateIndexStmt) SQL

func (s *CreateIndexStmt) SQL() string

SQL returns the built SQL string.

type CreateTableStmt

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

CreateTableStmt is CREATE TABLE statement.

func (*CreateTableStmt) Column

func (s *CreateTableStmt) Column(column, typ string) icreatetable.Column

Column calls table column definition.

func (*CreateTableStmt) Cons

func (s *CreateTableStmt) Cons(key string) icreatetable.Cons

Cons calls CONSTRAINT option.

func (*CreateTableStmt) Default

func (s *CreateTableStmt) Default(value interface{}) icreatetable.Default

Default calls DEFAULT option.

func (*CreateTableStmt) Foreign

func (s *CreateTableStmt) Foreign(columns ...string) icreatetable.Foreign

Foreign calls FOREIGN KEY keyword.

func (*CreateTableStmt) Migrate

func (s *CreateTableStmt) Migrate() error

Migrate executes database migration.

func (*CreateTableStmt) Model

func (s *CreateTableStmt) Model(model interface{}) icreatetable.Model

Model sets model to CreateTableStmt.

func (*CreateTableStmt) NotNull

func (s *CreateTableStmt) NotNull() icreatetable.NotNull

NotNull calls NOT NULL option.

func (*CreateTableStmt) Primary

func (s *CreateTableStmt) Primary(columns ...string) icreatetable.Primary

Primary calls PRIMARY KEY keyword.

func (*CreateTableStmt) RawClause

func (s *CreateTableStmt) RawClause(raw string, values ...interface{}) icreatetable.RawClause

RawClause calls the raw string clause.

func (*CreateTableStmt) Ref

func (s *CreateTableStmt) Ref(table string, columns ...string) icreatetable.Ref

Ref calls REFERENCES keyword.

func (*CreateTableStmt) SQL

func (s *CreateTableStmt) SQL() string

SQL returns the built SQL string.

func (*CreateTableStmt) Unique

func (s *CreateTableStmt) Unique(columns ...string) icreatetable.Unique

Unique calls UNIQUE keyword.

type DB

type DB interface {
	SetConnMaxLifetime(n time.Duration) error
	SetMaxIdleConns(n int) error
	SetMaxOpenConns(n int) error
	Close() error
	Begin() (Tx, error)
	// contains filtered or unexported methods
}

DB is the interface of database.

func Open

func Open(driver, dsn string) (DB, error)

Open opens the database connection.

type DeleteStmt

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

DeleteStmt is DELETE statement.

func (*DeleteStmt) And

func (s *DeleteStmt) And(expr string, values ...interface{}) idelete.And

And calls AND clause.

func (*DeleteStmt) Clauses

func (s *DeleteStmt) Clauses() []interfaces.Clause

Clauses returns the called clauses.

func (*DeleteStmt) Cmd

func (s *DeleteStmt) Cmd() interfaces.Clause

Cmd returns the command clause.

func (*DeleteStmt) CompareWith

func (s *DeleteStmt) CompareWith(targetStmt interfaces.Stmt) error

CompareWith compares the statements and returns error if the statements is not same. In this case, same means that stmt.cmd and stmt.called is corresponding.

func (*DeleteStmt) Exec

func (s *DeleteStmt) Exec() error

Exec executed SQL statement without mapping to model. If type of conn is gsorm.MockDB, compare statements between called and expected.

func (*DeleteStmt) From

func (s *DeleteStmt) From(tables ...string) idelete.From

From calls FROM clause.

func (*DeleteStmt) Or

func (s *DeleteStmt) Or(expr string, values ...interface{}) idelete.Or

Or calls OR clause.

func (*DeleteStmt) RawClause

func (s *DeleteStmt) RawClause(raw string, values ...interface{}) idelete.RawClause

RawClause calls the raw string clause.

func (*DeleteStmt) SQL

func (s *DeleteStmt) SQL() string

SQL returns the built SQL string.

func (*DeleteStmt) String

func (s *DeleteStmt) String() string

String returns the method calls as string.

func (*DeleteStmt) Where

func (s *DeleteStmt) Where(expr string, values ...interface{}) idelete.Where

Where calls WHERE clause.

type DropDBStmt

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

DropDBStmt is DROP DATABASE statement.

func (*DropDBStmt) Migrate

func (s *DropDBStmt) Migrate() error

Migrate executes database migration.

func (*DropDBStmt) RawClause

func (s *DropDBStmt) RawClause(raw string, value ...interface{}) idropdb.RawClause

RawClause calls the raw string clause.

func (*DropDBStmt) SQL

func (s *DropDBStmt) SQL() string

SQL returns the built SQL string.

type DropTableStmt

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

DropTableStmt is DROP TABLE statement.

func (*DropTableStmt) Migrate

func (s *DropTableStmt) Migrate() error

Migrate executes database migration.

func (*DropTableStmt) RawClause

func (s *DropTableStmt) RawClause(raw string, value ...interface{}) idroptable.RawClause

RawClause calls the raw string clause.

func (*DropTableStmt) SQL

func (s *DropTableStmt) SQL() string

SQL returns the built SQL string.

type InsertStmt

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

InsertStmt is INSERT statement.

func (*InsertStmt) Clauses

func (s *InsertStmt) Clauses() []interfaces.Clause

Clauses returns the called clauses.

func (*InsertStmt) Cmd

func (s *InsertStmt) Cmd() interfaces.Clause

Cmd returns the command clause.

func (*InsertStmt) CompareWith

func (s *InsertStmt) CompareWith(targetStmt interfaces.Stmt) error

CompareWith compares the statements and returns error if the statements is not same. In this case, same means that stmt.cmd and stmt.called is corresponding.

func (*InsertStmt) Exec

func (s *InsertStmt) Exec() error

Exec executed SQL statement without mapping to model. If type of conn is gsorm.MockDB, compare statements between called and expected.

func (*InsertStmt) Model

func (s *InsertStmt) Model(model interface{}) iinsert.Model

Model sets model to InsertStmt.

func (*InsertStmt) RawClause

func (s *InsertStmt) RawClause(raw string, values ...interface{}) iinsert.RawClause

RawClause calls the raw string clause.

func (*InsertStmt) SQL

func (s *InsertStmt) SQL() string

SQL returns the built SQL string.

func (*InsertStmt) Select

func (s *InsertStmt) Select(stmt interfaces.Stmt) iinsert.Select

Select calls SELECT statement.

func (*InsertStmt) String

func (s *InsertStmt) String() string

String returns the method calls as string.

func (*InsertStmt) Values

func (s *InsertStmt) Values(values ...interface{}) iinsert.Values

Values calls VALUES clause.

type Mock

type Mock interface {
	Complete() error
	Expect(s interfaces.Stmt)
	ExpectWithReturn(s interfaces.Stmt, v interface{})
	// contains filtered or unexported methods
}

Mock is mock database connection pool.

type MockDB

type MockDB interface {
	Mock
	DB
	ExpectBegin() MockTx
}

MockDB is interface of mock database.

func OpenMock

func OpenMock() MockDB

OpenMock opens the mock database connection.

type MockTx

type MockTx interface {
	Mock
	Tx
	ExpectCommit()
	ExpectRollback()
}

MockTx is interface of mock transaction.

type SelectStmt

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

SelectStmt is SELECT statement.

func (*SelectStmt) And

func (s *SelectStmt) And(expr string, values ...interface{}) iselect.And

And calls AND clause.

func (*SelectStmt) Clauses

func (s *SelectStmt) Clauses() []interfaces.Clause

Clauses returns the called clauses.

func (*SelectStmt) Cmd

func (s *SelectStmt) Cmd() interfaces.Clause

Cmd returns the command clause.

func (*SelectStmt) CompareWith

func (s *SelectStmt) CompareWith(targetStmt interfaces.Stmt) error

CompareWith compares the statements and returns error if the statements is not same. In this case, same means that stmt.cmd and stmt.called is corresponding.

func (*SelectStmt) From

func (s *SelectStmt) From(tables ...string) iselect.From

From calls FROM clause.

func (*SelectStmt) GroupBy

func (s *SelectStmt) GroupBy(columns ...string) iselect.GroupBy

GroupBy calls GROUP BY clause.

func (*SelectStmt) Having

func (s *SelectStmt) Having(expr string, values ...interface{}) iselect.Having

Having calls HAVING clause.

func (*SelectStmt) Join

func (s *SelectStmt) Join(table string) iselect.Join

Join calls (INNER) JOIN clause.

func (*SelectStmt) LeftJoin

func (s *SelectStmt) LeftJoin(table string) iselect.Join

LeftJoin calls (INNER) JOIN clause.

func (*SelectStmt) Limit

func (s *SelectStmt) Limit(limit int) iselect.Limit

Limit calls LIMIT clause.

func (*SelectStmt) Offset

func (s *SelectStmt) Offset(offset int) iselect.Offset

Offset calls OFFSET clause.

func (*SelectStmt) On

func (s *SelectStmt) On(expr string, values ...interface{}) iselect.On

On calls ON clause.

func (*SelectStmt) Or

func (s *SelectStmt) Or(expr string, values ...interface{}) iselect.Or

Or calls OR clause.

func (*SelectStmt) OrderBy

func (s *SelectStmt) OrderBy(columns ...string) iselect.OrderBy

OrderBy calls ORDER BY clause.

func (*SelectStmt) Query

func (s *SelectStmt) Query(model interface{}) error

Query executes SQL statement with mapping to model. If type of (*SelectStmt).conn is gsorm.MockDB, compare statements between called and expected. Then, it maps expected values to model.

func (*SelectStmt) RawClause

func (s *SelectStmt) RawClause(raw string, values ...interface{}) iselect.RawClause

RawClause calls the raw string clause.

func (*SelectStmt) RightJoin

func (s *SelectStmt) RightJoin(table string) iselect.Join

RightJoin calls (INNER) JOIN clause.

func (*SelectStmt) SQL

func (s *SelectStmt) SQL() string

SQL returns the built SQL string.

func (*SelectStmt) String

func (s *SelectStmt) String() string

String returns the method calls as string.

func (*SelectStmt) Union

func (s *SelectStmt) Union(stmt interfaces.Stmt) iselect.Union

Union calls UNION clause.

func (*SelectStmt) UnionAll

func (s *SelectStmt) UnionAll(stmt interfaces.Stmt) iselect.Union

UnionAll calls UNION ALL clause.

func (*SelectStmt) Where

func (s *SelectStmt) Where(expr string, values ...interface{}) iselect.Where

Where calls WHERE clause.

type Tx

type Tx interface {
	Commit() error
	Rollback() error
	// contains filtered or unexported methods
}

Tx is the interface of database transaction.

type UpdateStmt

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

UpdateStmt is UPDATE statement..

func (*UpdateStmt) And

func (s *UpdateStmt) And(expr string, values ...interface{}) iupdate.And

And calls AND clause.

func (*UpdateStmt) Clauses

func (s *UpdateStmt) Clauses() []interfaces.Clause

Clauses returns the called clauses.

func (*UpdateStmt) Cmd

func (s *UpdateStmt) Cmd() interfaces.Clause

Cmd returns the command clause.

func (*UpdateStmt) CompareWith

func (s *UpdateStmt) CompareWith(targetStmt interfaces.Stmt) error

CompareWith compares the statements and returns error if the statements is not same. In this case, same means that stmt.cmd and stmt.called is corresponding.

func (*UpdateStmt) Exec

func (s *UpdateStmt) Exec() error

Exec executes SQL statement without mapping to model. If type of conn is gsorm.MockDB, compare statements between called and expected.

func (*UpdateStmt) Model

func (s *UpdateStmt) Model(model interface{}, columns ...string) iupdate.Model

Model sets model to UpdateStmt.

func (*UpdateStmt) Or

func (s *UpdateStmt) Or(expr string, values ...interface{}) iupdate.Or

Or calls OR clause.

func (*UpdateStmt) RawClause

func (s *UpdateStmt) RawClause(raw string, values ...interface{}) iupdate.RawClause

RawClause calls the raw string clause.

func (*UpdateStmt) SQL

func (s *UpdateStmt) SQL() string

SQL returns the built SQL string.

func (*UpdateStmt) Set

func (s *UpdateStmt) Set(column string, value interface{}) iupdate.Set

Set calls SET clause.

func (*UpdateStmt) String

func (s *UpdateStmt) String() string

String returns the method calls as string.

func (*UpdateStmt) Where

func (s *UpdateStmt) Where(expr string, values ...interface{}) iupdate.Where

Where calls WHERE clause.

Jump to

Keyboard shortcuts

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