Documentation ¶
Overview ¶
Package genmai provides simple, better and easy-to-use Object-Relational Mapper.
Example ¶
package main import ( "fmt" "log" _ "github.com/mattn/go-sqlite3" "github.com/naoina/genmai" ) type TestModel struct { Id int64 Name string Addr string } func main() { db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } defer db.Close() for _, query := range []string{ `CREATE TABLE test_model ( id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL, addr TEXT NOT NULL )`, `INSERT INTO test_model VALUES (1, 'test1', 'addr1')`, `INSERT INTO test_model VALUES (2, 'test2', 'addr2')`, `INSERT INTO test_model VALUES (3, 'test3', 'addr3')`, } { if _, err := db.DB().Exec(query); err != nil { log.Fatal(err) } } var results []TestModel // SELECT * FROM "test_model"; if err := db.Select(&results); err != nil { log.Fatal(err) } fmt.Println(results) }
Output: [{1 test1 addr1} {2 test2 addr2} {3 test3 addr3}]
Index ¶
- Variables
- func ColumnName(d Dialect, tname, cname string) string
- func IsUnexportedField(field reflect.StructField) bool
- func ToInterfaceSlice(slice []string) []interface{}
- type AfterDeleter
- type AfterInserter
- type AfterUpdater
- type BeforeDeleter
- type BeforeInserter
- type BeforeUpdater
- type Clause
- type Condition
- func (c *Condition) And(cond interface{}, args ...interface{}) *Condition
- func (c *Condition) Between(from, to interface{}) *Condition
- func (c *Condition) In(args ...interface{}) *Condition
- func (c *Condition) IsNotNull() *Condition
- func (c *Condition) IsNull() *Condition
- func (c *Condition) Like(arg string) *Condition
- func (c *Condition) Limit(lim int) *Condition
- func (c *Condition) Offset(offset int) *Condition
- func (c *Condition) Or(cond interface{}, args ...interface{}) *Condition
- func (c *Condition) OrderBy(table, col interface{}, order ...interface{}) *Condition
- func (c *Condition) Where(cond interface{}, args ...interface{}) *Condition
- type DB
- func (db *DB) Begin() error
- func (db *DB) Close() error
- func (db *DB) Commit() error
- func (db *DB) Count(column ...interface{}) *Function
- func (db *DB) CreateIndex(table interface{}, name string, names ...string) error
- func (db *DB) CreateTable(table interface{}) error
- func (db *DB) CreateTableIfNotExists(table interface{}) error
- func (db *DB) CreateUniqueIndex(table interface{}, name string, names ...string) error
- func (db *DB) DB() *sql.DB
- func (db *DB) Delete(obj interface{}) (affected int64, err error)
- func (db *DB) Distinct(columns ...string) *Distinct
- func (db *DB) DropTable(table interface{}) error
- func (db *DB) From(arg interface{}) *From
- func (db *DB) Insert(obj interface{}) (affected int64, err error)
- func (db *DB) Join(table interface{}) *JoinCondition
- func (db *DB) LastInsertId() (int64, error)
- func (db *DB) LeftJoin(table interface{}) *JoinCondition
- func (db *DB) Limit(lim int) *Condition
- func (db *DB) Offset(offset int) *Condition
- func (db *DB) OrderBy(table interface{}, column interface{}, order ...interface{}) *Condition
- func (db *DB) Quote(s string) string
- func (db *DB) Raw(v interface{}) Raw
- func (db *DB) Rollback() error
- func (db *DB) Select(output interface{}, args ...interface{}) (err error)
- func (db *DB) SetLogFormat(format string) error
- func (db *DB) SetLogOutput(w io.Writer)
- func (db *DB) Update(obj interface{}) (affected int64, err error)
- func (db *DB) Where(cond interface{}, args ...interface{}) *Condition
- type Dialect
- type Distinct
- type Float32
- type Float64
- type From
- type Function
- type JoinCondition
- type MySQLDialect
- func (d *MySQLDialect) AutoIncrement() string
- func (d *MySQLDialect) FormatBool(b bool) string
- func (d *MySQLDialect) LastInsertId() string
- func (d *MySQLDialect) Name() string
- func (d *MySQLDialect) PlaceHolder(i int) string
- func (d *MySQLDialect) Quote(s string) string
- func (d *MySQLDialect) SQLType(v interface{}, autoIncrement bool, size uint64) (name string, allowNull bool)
- type Order
- type PostgresDialect
- func (d *PostgresDialect) AutoIncrement() string
- func (d *PostgresDialect) FormatBool(b bool) string
- func (d *PostgresDialect) LastInsertId() string
- func (d *PostgresDialect) Name() string
- func (d *PostgresDialect) PlaceHolder(i int) string
- func (d *PostgresDialect) Quote(s string) string
- func (d *PostgresDialect) SQLType(v interface{}, autoIncrement bool, size uint64) (name string, allowNull bool)
- type Rat
- type Raw
- type SQLite3Dialect
- func (d *SQLite3Dialect) AutoIncrement() string
- func (d *SQLite3Dialect) FormatBool(b bool) string
- func (d *SQLite3Dialect) LastInsertId() string
- func (d *SQLite3Dialect) Name() string
- func (d *SQLite3Dialect) PlaceHolder(i int) string
- func (d *SQLite3Dialect) Quote(s string) string
- func (d *SQLite3Dialect) SQLType(v interface{}, autoIncrement bool, size uint64) (name string, allowNull bool)
- type TableNamer
- type TimeStamp
Examples ¶
- Package
- DB.Select (All)
- DB.Select (Between)
- DB.Select (Columns)
- DB.Select (Complex)
- DB.Select (Count)
- DB.Select (CountDistinct)
- DB.Select (Distinct)
- DB.Select (In)
- DB.Select (InWithSlice)
- DB.Select (Join)
- DB.Select (JoinWithSpecificTable)
- DB.Select (LeftJoin)
- DB.Select (Like)
- DB.Select (Limit)
- DB.Select (Offset)
- DB.Select (OrderBy)
- DB.Select (OrderByMultiple)
- DB.Select (OrderByWithSpecificTable)
- DB.Select (Where)
- DB.Select (WhereAnd)
- DB.Select (WhereNested)
Constants ¶
This section is empty.
Variables ¶
var ErrTxDone = errors.New("genmai: transaction hasn't been started or already committed or rolled back")
var (
ErrUsingFloatType = errors.New("float types have a rounding error problem.\n" +
"Please use `genmai.Rat` if you want an exact value.\n" +
"However, if you still want a float types, please use `genmai.Float32` and `Float64`.")
)
Functions ¶
func ColumnName ¶
columnName returns the column name that added the table name with quoted if needed.
func IsUnexportedField ¶
func IsUnexportedField(field reflect.StructField) bool
IsUnexportedField returns whether the field is unexported. This function is to avoid the bug in versions older than Go1.3. See following links:
https://code.google.com/p/go/issues/detail?id=7247 http://golang.org/ref/spec#Exported_identifiers
func ToInterfaceSlice ¶
func ToInterfaceSlice(slice []string) []interface{}
ToInterfaceSlice convert to []interface{} from []string.
Types ¶
type AfterDeleter ¶
type AfterDeleter interface { // AfterDelete called after a delete by DB.Delete. AfterDelete() error }
AfterDeleter is an interface that hook for after Delete.
type AfterInserter ¶
type AfterInserter interface { // AfterInsert called after an insert by DB.Insert. AfterInsert() error }
AfterInserter is an interface that hook for after Insert.
type AfterUpdater ¶
type AfterUpdater interface { // AfterUpdate called after an update by DB.Update. AfterUpdate() error }
AfterUpdater is an interface that hook for after Update.
type BeforeDeleter ¶
type BeforeDeleter interface { // BeforeDelete called before a delete by DB.Delete. // If it returns error, the delete will be cancelled. BeforeDelete() error }
BeforeDeleter is an interface that hook for before Delete.
type BeforeInserter ¶
type BeforeInserter interface { // BeforeInsert called before an insert by DB.Insert. // If it returns error, the insert will be cancelled. BeforeInsert() error }
BeforeInserter is an interface that hook for before Insert.
type BeforeUpdater ¶
type BeforeUpdater interface { // BeforeUpdate called before an update by DB.Update. // If it returns error, the update will be cancelled. BeforeUpdate() error }
BeforeUpdater is an interface that hook for before Update.
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
Condition represents a condition for query.
func (*Condition) Between ¶
Between adds "BETWEEN ... AND ..." clause to the Condition and returns it for method chain.
func (*Condition) IsNotNull ¶
IsNotNull adds "IS NOT NULL" clause to the Condition and returns it for method chain.
func (*Condition) IsNull ¶
IsNull adds "IS NULL" clause to the Condition and returns it for method chain.
func (*Condition) Limit ¶
Limit adds "LIMIT" clause to the Condition and returns it for method chain.
func (*Condition) Offset ¶
Offset adds "OFFSET" clause to the Condition and returns it for method chain.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a database object.
func (*DB) Commit ¶
Commit commits the transaction. If Begin still not called, or Commit or Rollback already called, Commit returns ErrTxDone.
func (*DB) CreateIndex ¶
CreateIndex creates the index into database. If table isn't direct/indirect struct, it returns error.
func (*DB) CreateTable ¶
CreateTable creates the table into database. If table isn't direct/indirect struct, it returns error.
func (*DB) CreateTableIfNotExists ¶
CreateTableIfNotExists creates the table into database if table isn't exists. If table isn't direct/indirect struct, it returns error.
func (*DB) CreateUniqueIndex ¶
CreateUniqueIndex creates the unique index into database. If table isn't direct/indirect struct, it returns error.
func (*DB) Delete ¶
Delete deletes the records from database table. The obj must be pointer to struct or slice of struct, and must have field that specified "pk" struct tag. Delete will try to delete record which searched by value of primary key in obj. Delete returns teh number of rows affected by a delete.
func (*DB) DropTable ¶
DropTable removes the table from database. If table isn't direct/indirect struct, it returns error.
func (*DB) From ¶
From returns a "FROM" statement. A table name will be determined from name of struct of arg. If arg argument is not struct type, it panics.
func (*DB) Insert ¶
Insert inserts one or more records to the database table. The obj must be pointer to struct or slice of struct. If a struct have a field which specified "pk" struct tag on type of autoincrementable, it won't be used to as an insert value. Insert sets the last inserted id to the primary key of the instance of the given obj if obj is single. Insert returns the number of rows affected by insert.
func (*DB) Join ¶
func (db *DB) Join(table interface{}) *JoinCondition
Join returns a new JoinCondition of "JOIN" clause.
func (*DB) LastInsertId ¶
func (*DB) LeftJoin ¶
func (db *DB) LeftJoin(table interface{}) *JoinCondition
func (*DB) Rollback ¶
Rollback rollbacks the transaction. If Begin still not called, or Commit or Rollback already called, Rollback returns ErrTxDone.
func (*DB) Select ¶
Select fetch data into the output from the database. output argument must be pointer to a slice of struct. If not a pointer or not a slice of struct, It returns error. The table name of the database will be determined from name of struct. e.g. If *[]ATableName passed to output argument, table name will be "a_table_name". If args are not given, fetch the all data like "SELECT * FROM table" SQL.
Example (All) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model"; if err := db.Select(&results); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Between) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" WHERE "id" BETWEEN 3 AND 5; if err := db.Select(&results, db.Where("id").Between(3, 5)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Columns) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model"."id", "test_model"."name" FROM "test_model"; if err := db.Select(&results, []string{"id", "name"}); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Complex) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model"."name" FROM "test_model" // WHERE "name" LIKE "%alice%" OR ("id" > 100 AND "id" < 200) OR ("id" BETWEEN 700 AND 1000) // ORDER BY "id" ASC LIMIT 2 OFFSET 5 if err := db.Select(&results, "name", db.Where("name"). Like("%alice%"). Or(db.Where("id", ">", 100).And("id", "<", 200)). Or(db.Where("id").Between(700, 1000)). Limit(2).Offset(5).OrderBy("id", genmai.ASC), ); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Count) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var result int64 // SELECT COUNT(*) FROM "test_model"; if err := db.Select(&result, db.Count(), db.From(TestModel{})); err != nil { log.Fatal(err) } fmt.Println(result)
Output:
Example (CountDistinct) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var result int64 // SELECT COUNT(DISTINCT "test_model"."name") FROM "test_model"; if err := db.Select(&result, db.Count(db.Distinct("name")), db.From(TestModel{})); err != nil { log.Fatal(err) } fmt.Println(result)
Output:
Example (Distinct) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT DISTINCT "test_model"."name" FROM "test_model"; if err := db.Select(&results, db.Distinct("name")); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (In) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" WHERE "id" IN (1, 3, 5); if err := db.Select(&results, db.Where("id").In(1, 3, 5)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (InWithSlice) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel values := []int64{1, 3, 5} // SELECT "test_model".* FROM "test_model" WHERE "id" IN (1, 3, 5); if err := db.Select(&results, db.Where("id").In(values)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Join) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } type M2 struct { Id int64 Body string } var results []TestModel // SELECT "test_model".* FROM "test_model" JOIN "m2" ON "test_model"."id" = "m2"."id"; if err := db.Select(&results, "name", db.Join(&M2{}).On("id")); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (JoinWithSpecificTable) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } type M2 struct { Id int64 Body string } type M3 struct { TestModelId int64 M2Id int64 } var results []TestModel // SELECT "test_model".* FROM "test_model" JOIN "m3" ON "test_model"."id" = "m3"."test_model_id" JOIN "m2" ON "m3"."m2_id" = "m2"."id"; if err := db.Select(&results, "name", db.Join(&M3{}).On("id", "=", "test_model_id"), db.Join(&M2{}).On(&M3{}, "m2_id", "=", "id")); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (LeftJoin) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" LEFT JOIN "m2" ON "test_model"."name" = "m2"."body" WHERE "m2"."body" IS NULL; if err := db.Select(&results, "name", db.LeftJoin(&M2{}).On("name", "=", "body").Where(&M2{}, "body").IsNull()); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Like) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" WHERE "name" LIKE "alice%"; if err := db.Select(&results, db.Where("name").Like("alice%")); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Limit) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" LIMIT 3; if err := db.Select(&results, db.Limit(3)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Offset) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" OFFSET 10; if err := db.Select(&results, db.Offset(10)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (OrderBy) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" ORDER BY "name" DESC; if err := db.Select(&results, db.OrderBy("name", genmai.DESC)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (OrderByMultiple) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" ORDER BY "name" DESC, "addr" DESC; if err := db.Select(&results, db.OrderBy("name", genmai.DESC, "addr", genmai.DESC)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (OrderByWithSpecificTable) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" ORDER BY "test_model"."name" DESC; if err := db.Select(&results, db.OrderBy(TestModel{}, "name", genmai.DESC)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (Where) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" WHERE "id" = 1; if err := db.Select(&results, db.Where("id", "=", 1)); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (WhereAnd) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" WHERE "id" = 1 AND "name" = "alice"; if err := db.Select(&results, db.Where("id", "=", 1).And("name", "=", "alice")); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
Example (WhereNested) ¶
db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:") if err != nil { log.Fatal(err) } var results []TestModel // SELECT "test_model".* FROM "test_model" WHERE "id" = 1 OR ("name" = "alice" AND "addr" != "Tokyo"); if err := db.Select(&results, db.Where("id", "=", 1).Or(db.Where("name", "=", "alice").And("addr", "!=", "Tokyo"))); err != nil { log.Fatal(err) } fmt.Println(results)
Output:
func (*DB) SetLogFormat ¶
SetLogFormat sets format for logging.
Format syntax uses Go's template. And you can use the following data object in that template.
- .time time.Time object in current time.
- .duration Processing time of SQL. It will format to "%.2fms".
- .query string of SQL query. If it using placeholder, placeholder parameters will append to the end of query.
The default format is:
[{{.time.Format "2006-01-02 15:04:05"}}] [{{.duration}}] {{.query}}
func (*DB) SetLogOutput ¶
SetLogOutput sets output destination for logging. If w is nil, it unsets output of logging.
type Dialect ¶
type Dialect interface { // Name returns a name of the dialect. // Return value must be same as the driver name. Name() string // Quote returns a quoted s. // It is for a column name, not a value. Quote(s string) string // PlaceHolder returns the placeholder character of the database. // A current number of placeholder will passed to i. PlaceHolder(i int) string // SQLType returns the SQL type of the v. // autoIncrement is whether the field is auto increment. // If "size" tag specified to struct field, it will passed to size // argument. If it doesn't specify, size is 0. SQLType(v interface{}, autoIncrement bool, size uint64) (name string, allowNull bool) // AutoIncrement returns the keyword of auto increment. AutoIncrement() string // FormatBool returns boolean value as string according to the value of b. FormatBool(b bool) string // LastInsertId returns an SQL to get the last inserted id. LastInsertId() string }
Dialect is an interface that the dialect of the database.
type Distinct ¶
type Distinct struct {
// contains filtered or unexported fields
}
Distinct represents a "DISTINCT" statement.
type Float32 ¶
type Float32 float32
type Float64 ¶
type Float64 float64
type Function ¶
type Function struct { // A function name. Name string // function arguments (optional). Args []interface{} }
Function represents a function of SQL.
type JoinCondition ¶
type JoinCondition struct {
// contains filtered or unexported fields
}
JoinCondition represents a condition of "JOIN" query.
func (*JoinCondition) Join ¶
func (jc *JoinCondition) Join(table interface{}) *JoinCondition
Join adds table name to the JoinCondition of "JOIN". If table isn't direct/indirect struct type, it panics.
func (*JoinCondition) LeftJoin ¶
func (jc *JoinCondition) LeftJoin(table interface{}) *JoinCondition
LeftJoin adds table name to the JoinCondition of "LEFT JOIN". If table isn't direct/indirect struct type, it panics.
func (*JoinCondition) On ¶
func (jc *JoinCondition) On(larg interface{}, args ...string) *Condition
On adds "[LEFT] JOIN ... ON" clause to the Condition and returns it for method chain.
type MySQLDialect ¶
type MySQLDialect struct{}
MySQLDialect represents a dialect of the MySQL. It implements the Dialect interface.
func (*MySQLDialect) AutoIncrement ¶
func (d *MySQLDialect) AutoIncrement() string
func (*MySQLDialect) FormatBool ¶
func (d *MySQLDialect) FormatBool(b bool) string
FormatBool returns "TRUE" or "FALSE" according to the value of b as boolean for MySQL.
func (*MySQLDialect) LastInsertId ¶
func (d *MySQLDialect) LastInsertId() string
func (*MySQLDialect) Name ¶
func (d *MySQLDialect) Name() string
Name returns name of the MySQLDialect.
func (*MySQLDialect) PlaceHolder ¶
func (d *MySQLDialect) PlaceHolder(i int) string
PlaceHolder returns the placeholder character of the MySQL.
func (*MySQLDialect) Quote ¶
func (d *MySQLDialect) Quote(s string) string
Quote returns a quoted s for a column name.
type PostgresDialect ¶
type PostgresDialect struct{}
PostgresDialect represents a dialect of the PostgreSQL. It implements the Dialect interface.
func (*PostgresDialect) AutoIncrement ¶
func (d *PostgresDialect) AutoIncrement() string
func (*PostgresDialect) FormatBool ¶
func (d *PostgresDialect) FormatBool(b bool) string
FormatBool returns "TRUE" or "FALSE" according to the value of b as boolean for PostgreSQL.
func (*PostgresDialect) LastInsertId ¶
func (d *PostgresDialect) LastInsertId() string
func (*PostgresDialect) Name ¶
func (d *PostgresDialect) Name() string
Name returns name of the PostgresDialect.
func (*PostgresDialect) PlaceHolder ¶
func (d *PostgresDialect) PlaceHolder(i int) string
PlaceHolder returns the placeholder character of the PostgreSQL.
func (*PostgresDialect) Quote ¶
func (d *PostgresDialect) Quote(s string) string
Quote returns a quoted s for a column name.
type Rat ¶
Rat is an wrapper of the Rat of math/big. However, Rat implements the sql Scanner interface.
type SQLite3Dialect ¶
type SQLite3Dialect struct{}
SQLite3Dialect represents a dialect of the SQLite3. It implements the Dialect interface.
func (*SQLite3Dialect) AutoIncrement ¶
func (d *SQLite3Dialect) AutoIncrement() string
func (*SQLite3Dialect) FormatBool ¶
func (d *SQLite3Dialect) FormatBool(b bool) string
FormatBool returns "1" or "0" according to the value of b as boolean for SQLite3.
func (*SQLite3Dialect) LastInsertId ¶
func (d *SQLite3Dialect) LastInsertId() string
func (*SQLite3Dialect) Name ¶
func (d *SQLite3Dialect) Name() string
Name returns name of the dialect.
func (*SQLite3Dialect) PlaceHolder ¶
func (d *SQLite3Dialect) PlaceHolder(i int) string
PlaceHolder returns the placeholder character of the SQLite3.
func (*SQLite3Dialect) Quote ¶
func (d *SQLite3Dialect) Quote(s string) string
Quote returns a quoted s for a column name.
type TableNamer ¶
type TableNamer interface { // TableName returns the table name on DB. TableName() string }
TableNamer is an interface that is used to use a different table name.
type TimeStamp ¶
type TimeStamp struct { // Time of creation. This field will be set automatically by BeforeInsert. CreatedAt time.Time `json:"created_at"` // Time of update. This field will be set by BeforeInsert or BeforeUpdate. UpdatedAt time.Time `json:"updated_at"` }
TimeStamp is fields for timestamps that commonly used.
func (*TimeStamp) BeforeInsert ¶
BeforeInsert sets current time to CreatedAt and UpdatedAt field. It always returns nil.
func (*TimeStamp) BeforeUpdate ¶
BeforeUpdate sets current time to UpdatedAt field. It always returns nil.