Documentation ¶
Index ¶
- Variables
- type Builder
- func (b *Builder) Begin() (builder *Builder, err error)
- func (b *Builder) Bind(destination interface{}) (builder *Builder)
- func (b *Builder) Commit() error
- func (b *Builder) Connect() (err error)
- func (b *Builder) Count() (count int)
- func (b *Builder) Delete() (builder *Builder, err error)
- func (b *Builder) Disconnect() (err error)
- func (b *Builder) Func(query string, data ...interface{}) Function
- func (b *Builder) Get(columns ...string) (builder *Builder, err error)
- func (b *Builder) GetOne(columns ...string) (builder *Builder, err error)
- func (b *Builder) GetValue(column string) (builder *Builder, err error)
- func (b *Builder) GetValues(column string) (builder *Builder, err error)
- func (b *Builder) GroupBy(columns ...string) (builder *Builder)
- func (b *Builder) Has() (builder *Builder, has bool, err error)
- func (b *Builder) Having(args ...interface{}) (builder *Builder)
- func (b *Builder) InnerJoin(table interface{}, condition string) (builder *Builder)
- func (b *Builder) Insert(data interface{}) (builder *Builder, err error)
- func (b *Builder) InsertMulti(data interface{}) (builder *Builder, err error)
- func (b *Builder) JoinOrWhere(table interface{}, args ...interface{}) (builder *Builder)
- func (b *Builder) JoinWhere(table interface{}, args ...interface{}) (builder *Builder)
- func (b *Builder) LeftJoin(table interface{}, condition string) (builder *Builder)
- func (b *Builder) Limit(from int, count ...int) (builder *Builder)
- func (b *Builder) Lock(tableNames ...string) (builder *Builder, err error)
- func (b *Builder) Migration() *Migration
- func (b *Builder) NaturalJoin(table interface{}, condition string) (builder *Builder)
- func (b *Builder) Now(formats ...string) Function
- func (b *Builder) OnDuplicate(columns []string, lastInsertID ...string) (builder *Builder)
- func (b *Builder) OrHaving(args ...interface{}) (builder *Builder)
- func (b *Builder) OrWhere(args ...interface{}) (builder *Builder)
- func (b *Builder) OrderBy(column string, args ...interface{}) (builder *Builder)
- func (b *Builder) Paginate(pageCount int, columns ...string) (builder *Builder, err error)
- func (b *Builder) Params() (params []interface{})
- func (b *Builder) Ping() (err error)
- func (b *Builder) Query() (query string)
- func (b *Builder) RawQuery(query string, values ...interface{}) (builder *Builder, err error)
- func (b *Builder) RawQueryOne(query string, values ...interface{}) (builder *Builder, err error)
- func (b *Builder) RawQueryValue(query string, values ...interface{}) (builder *Builder, err error)
- func (b *Builder) RawQueryValues(query string, values ...interface{}) (builder *Builder, err error)
- func (b *Builder) Replace(data interface{}) (builder *Builder, err error)
- func (b *Builder) RightJoin(table interface{}, condition string) (builder *Builder)
- func (b *Builder) Rollback() error
- func (b *Builder) SetLockMethod(method string) (builder *Builder)
- func (b *Builder) SetQueryOption(options ...string) (builder *Builder)
- func (b *Builder) SetTrace(status bool) (builder *Builder)
- func (b *Builder) SubQuery(alias ...string) (subQuery *SubQuery)
- func (b *Builder) Table(tableName ...string) (builder *Builder)
- func (b *Builder) Unlock(tableNames ...string) (builder *Builder, err error)
- func (b *Builder) Update(data interface{}) (builder *Builder, err error)
- func (b *Builder) Where(args ...interface{}) (builder *Builder)
- func (b *Builder) WithTotalCount() (builder *Builder)
- type CharsetType
- type CollationType
- type DB
- type EngineType
- type Function
- type Migration
- func (m *Migration) AutoIncrement() *Migration
- func (m *Migration) BigInt(length int) *Migration
- func (m *Migration) Binary(length int) *Migration
- func (m *Migration) Bit(length int) *Migration
- func (m *Migration) Blob() *Migration
- func (m *Migration) Char(length int) *Migration
- func (m *Migration) Charset(charset CharsetType) *Migration
- func (m *Migration) Collation(collation CollationType) *Migration
- func (m *Migration) Column(name string) *Migration
- func (m *Migration) Comment(text string) *Migration
- func (m *Migration) Create() (err error)
- func (m *Migration) Date() *Migration
- func (m *Migration) DateTime() *Migration
- func (m *Migration) Decimal(length ...int) *Migration
- func (m *Migration) Default(value interface{}) *Migration
- func (m *Migration) Double(length ...int) *Migration
- func (m *Migration) Drop(tableNames ...string) error
- func (m *Migration) DropIfExists(tableNames ...string) error
- func (m *Migration) Engine(engine EngineType) *Migration
- func (m *Migration) Enum(types ...interface{}) *Migration
- func (m *Migration) Float(length ...int) *Migration
- func (m *Migration) Foreign(args ...interface{}) *Migration
- func (m *Migration) Index(args ...interface{}) *Migration
- func (m *Migration) Int(length int) *Migration
- func (m *Migration) LongBlob() *Migration
- func (m *Migration) LongText() *Migration
- func (m *Migration) MediumBlob() *Migration
- func (m *Migration) MediumInt(length int) *Migration
- func (m *Migration) MediumText() *Migration
- func (m *Migration) Nullable() *Migration
- func (m *Migration) OnDelete(action string) *Migration
- func (m *Migration) OnUpdate(action string) *Migration
- func (m *Migration) Primary(args ...interface{}) *Migration
- func (m *Migration) Set(types ...interface{}) *Migration
- func (m *Migration) SmallInt(length int) *Migration
- func (m *Migration) Table(tableName string, comment ...string) *Migration
- func (m *Migration) Text() *Migration
- func (m *Migration) Time() *Migration
- func (m *Migration) Timestamp() *Migration
- func (m *Migration) TinyBlob() *Migration
- func (m *Migration) TinyInt(length int) *Migration
- func (m *Migration) TinyText() *Migration
- func (m *Migration) Unique(args ...interface{}) *Migration
- func (m *Migration) Unsigned() *Migration
- func (m *Migration) VarBinary(length int) *Migration
- func (m *Migration) Varchar(length int) *Migration
- func (m *Migration) Year() *Migration
- type SubQuery
- func (s *SubQuery) Get(columns ...string) (subQuery *SubQuery)
- func (s *SubQuery) GroupBy(columns ...string) (subQuery *SubQuery)
- func (s *SubQuery) Having(args ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) InnerJoin(table interface{}, condition string) (subQuery *SubQuery)
- func (s *SubQuery) JoinOrWhere(table interface{}, args ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) JoinWhere(table interface{}, args ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) LeftJoin(table interface{}, condition string) (subQuery *SubQuery)
- func (s *SubQuery) Limit(from int, count ...int) (subQuery *SubQuery)
- func (s *SubQuery) NaturalJoin(table interface{}, condition string) (subQuery *SubQuery)
- func (s *SubQuery) OrHaving(args ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) OrWhere(args ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) OrderBy(column string, args ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) Paginate(pageCount int, columns ...string) (subQuery *SubQuery)
- func (s *SubQuery) RawQuery(query string, values ...interface{}) (subQuery *SubQuery)
- func (s *SubQuery) RightJoin(table interface{}, condition string) (subQuery *SubQuery)
- func (s *SubQuery) Table(tableName ...string) (subQuery *SubQuery)
- func (s *SubQuery) Where(args ...interface{}) (subQuery *SubQuery)
- type Timestamp
- func (t Timestamp) IsDate(date string) Timestamp
- func (t Timestamp) IsDay(day int) Timestamp
- func (t Timestamp) IsHour(hour int) Timestamp
- func (t Timestamp) IsMinute(minute int) Timestamp
- func (t Timestamp) IsMonth(month interface{}) Timestamp
- func (t Timestamp) IsSecond(second int) Timestamp
- func (t Timestamp) IsWeekday(weekday interface{}) Timestamp
- func (t Timestamp) IsYear(year int) Timestamp
- type Trace
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPointer 是會在資料的映射目的地為 nil 指標時所發生的錯誤。 ErrInvalidPointer = errors.New("reiner: the destination of the result is an invalid pointer") // ErrIncorrectDataType 是個會在插入、更新資料時傳入非 `map[string]interface` 資料型態參數時所發生的錯誤。 ErrIncorrectDataType = errors.New("reiner: the data type must be a `map[string]interface`") // ErrUnbegunTransaction 會在執行尚未透過 `Begin` 初始化的交易時所發生的錯誤。 ErrUnbegunTransaction = errors.New("reiner: calling the transaction function without `Begin()`") // ErrNoTable 是個會在未指定資料表格時所發生的錯誤。 ErrNoTable = errors.New("reiner: no table was specified") )
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct { // Timestamp 是時間戳的相關輔助函式。 Timestamp *Timestamp // Traces 是最後執行的 SQL 指令蹤跡資訊,適合用於效能除錯上。 Traces []Trace // TotalCount 是結果的總計筆數。 TotalCount int // PageLimit 限制了一頁僅能有幾筆資料。 PageLimit int // TotalPage 是結果的總計頁數。 TotalPage int // LasyQuery 是最後所執行的 SQL 指令。 LastQuery string // LastInsertID 是最後所插入的資料 ID 編號。 LastInsertID int // LastParams 是最後執行時的參數資料。 LastParams []interface{} // LastResult 是最後執行時的 `sql.Result` 資料。 LastResult sql.Result // contains filtered or unexported fields }
Builder 是個資料庫的 SQL 指令建置系統,同時也帶有資料庫的連線資料。
func New ¶
New 會建立一個新的連線並且提供 MySQL 的 SQL 指令建置系統。當沒有傳入參數時, 會變成 SQL 指令建置模式,而這個情況下你可以透過 Reiner 來建立 SQL 查詢指令。
.New()
如果要連接到一個資料庫,第一個參數則需要傳入主要資料庫的 DSN(資料來源名稱)。
.New("root:root@/master")
若需要讀/寫區分,第一個參數則是為主要資料庫的 DSN,而其餘的則是 Slave 資料庫的 DSN。
.New("root:root@/master", root:root@/slave") .New("root:root@/master", []string{"root:root@/slave", "root:root@/slave2"})
查看 https://dev.mysql.com/doc/refman/5.7/en/replication-solutions-scaleout.html 了解更多資訊。
func (*Builder) GetOne ¶
GetOne 會取得僅單列的資料作為結果,傳入的參數為欲取得的欄位名稱,不傳入參數表示取得所有欄位。 簡單說,這就是 `.Limit(1).Get()` 的縮寫用法。
func (*Builder) InsertMulti ¶
InsertMulti 會一次插入多筆資料。
func (*Builder) JoinOrWhere ¶
JoinOrWhere 能夠建立一個基於 `WHERE OR` 的條件式給某個指定的插入資料表格。
func (*Builder) NaturalJoin ¶
NaturalJoin 會自然插入一個資料表格。
func (*Builder) Now ¶
Now 會回傳一個基於 `INTERVAL` 的 SQL 資料庫函式, 傳入的參數格式可以是 `+1Y`、`-2M`,同時也可以像 `Now("+1Y", "-2M")` 一樣地串連使用。 支援的格式為:`Y`(年)、`M`(月)、`D`(日)、`W`(星期)、`h`(小時)、`m`(分鐘)、`s`(秒數)。
func (*Builder) OnDuplicate ¶
OnDuplicate 能夠指定欲更新的欄位名稱,這會在插入的資料重複時自動更新相對應的欄位。
func (*Builder) Paginate ¶
Paginate 基本上和 `Get` 取得函式無異,但此函式能夠自動依照分頁數來推算該從哪裡繼續取得資料。 使用時須先確定是否有指定 `PageLimit`(預設為:20),這樣才能限制一頁有多少筆資料。
func (*Builder) Params ¶
func (b *Builder) Params() (params []interface{})
Params returns the last used parameters, it's the same as `LastParams` but the name is more meaningful.
func (*Builder) RawQuery ¶
RawQuery 會接收傳入的變數來執行傳入的 SQL 執行語句,變數可以在語句中以 `?`(Prepared Statements)使用來避免 SQL 注入攻擊。 這會將多筆資料映射到本地的建構體切片、陣列上。
func (*Builder) RawQueryOne ¶
RawQueryOne 與 RawQuery 使用方法相同,但這會在 SQL 指令後追加 `LIMIT 1` 且僅會將單筆資料映射到本地的建構體、`map`。
func (*Builder) RawQueryValue ¶
RawQueryValue 與 RawQuery 使用方法相同,但這會在 SQL 指令後追加 `LIMIT 1` 並將單個欄位的資料映射到本地的變數(字串、正整數), 這很適合用於像是你想要取得單個使用者暱稱的時候。
func (*Builder) RawQueryValues ¶
RawQueryValues 與 RawQuery 使用方法相同,但這會將多筆單個欄位的資料映射到本地的字串、正整數切片、陣列。 這很適合用於像是你想要取得多個使用者暱稱陣列的時候。
func (*Builder) SetLockMethod ¶
SetLockMethod 會設置鎖定資料表格的方式(例如:`WRITE`、`READ`)。
func (*Builder) SetQueryOption ¶
SetQueryOption 會設置 SQL 指令的額外選項(例如:`SQL_NO_CACHE`)。
func (*Builder) SetTrace ¶
SetTrace 會決定蹤跡模式的開關,當設置為 `true` 時會稍微地拖慢效能, 但你就能夠從 `Trace` 屬性中取得 SQL 執行後的堆疊與路徑結果。
func (*Builder) SubQuery ¶
SubQuery 能夠將目前的 SQL 指令轉換為子指令(Sub Query)來防止建置後直接被執行,這讓你可以將子指令傳入其他的條件式(例如:`WHERE`), 若欲將子指令傳入插入(Join)條件中,必須在參數指定此子指令的別名。
func (*Builder) WithTotalCount ¶
WithTotalCount 會在 SQL 執行指令中安插 `SQL_CALC_FOUND_ROWS` 選項, 如此一來就能夠在執行完 SQL 指令後取得查詢的總計行數。在不同情況下,這可能會拖低執行效能。
type CharsetType ¶
type CharsetType string
CharsetType 是資料表的字符集格式。
const ( // CharsetBig5 是用於資料庫表格的 `big5` 字符集。 CharsetBig5 CharsetType = "big5" // CharsetDEC8 是用於資料庫表格的 `dec8` 字符集。 CharsetDEC8 CharsetType = "dec8" // CharsetCP850 是用於資料庫表格的 `cp850` 字符集。 CharsetCP850 CharsetType = "cp850" // CharsetHP8 是用於資料庫表格的 `hp8` 字符集。 CharsetHP8 CharsetType = "hp8" // CharsetKOI8R 是用於資料庫表格的 `koi8r` 字符集。 CharsetKOI8R CharsetType = "koi8r" // CharsetLatin1 是用於資料庫表格的 `latin1` 字符集。 CharsetLatin1 CharsetType = "latin1" // CharsetLatin2 是用於資料庫表格的 `latin2` 字符集。 CharsetLatin2 CharsetType = "latin2" // CharsetSwe7 是用於資料庫表格的 `swe7` 字符集。 CharsetSwe7 CharsetType = "swe7" // CharsetASCII 是用於資料庫表格的 `ascii` 字符集。 CharsetASCII CharsetType = "ascii" // CharsetUJIS 是用於資料庫表格的 `ujis` 字符集。 CharsetUJIS CharsetType = "ujis" // CharsetSJIS 是用於資料庫表格的 `sjis` 字符集。 CharsetSJIS CharsetType = "sjis" // CharsetHebrew 是用於資料庫表格的 `hebrew` 字符集。 CharsetHebrew CharsetType = "hebrew" // CharsetTIS620 是用於資料庫表格的 `tis620` 字符集。 CharsetTIS620 CharsetType = "tis620" // CharsetEUCKR 是用於資料庫表格的 `euckr` 字符集。 CharsetEUCKR CharsetType = "euckr" // CharsetKOI8U 是用於資料庫表格的 `koi8u` 字符集。 CharsetKOI8U CharsetType = "koi8u" // CharsetGB2312 是用於資料庫表格的 `gb2312` 字符集。 CharsetGB2312 CharsetType = "gb2312" // CharsetGreek 是用於資料庫表格的 `greek` 字符集。 CharsetGreek CharsetType = "greek" // CharsetCP1250 是用於資料庫表格的 `cp1250` 字符集。 CharsetCP1250 CharsetType = "cp1250" // CharsetGBK 是用於資料庫表格的 `gbk` 字符集。 CharsetGBK CharsetType = "gbk" // CharsetLatin5 是用於資料庫表格的 `latin5` 字符集。 CharsetLatin5 CharsetType = "latin5" // CharsetARMSCII8 是用於資料庫表格的 `armscii8` 字符集。 CharsetARMSCII8 CharsetType = "armscii8" // CharsetUTF8 是用於資料庫表格的 `utf8` 字符集。 CharsetUTF8 CharsetType = "utf8" // CharsetUCS2 是用於資料庫表格的 `ucs2` 字符集。 CharsetUCS2 CharsetType = "ucs2" // CharsetCP866 是用於資料庫表格的 `cp866` 字符集。 CharsetCP866 CharsetType = "cp866" // CharsetKeybcs2 是用於資料庫表格的 `keybcs2` 字符集。 CharsetKeybcs2 CharsetType = "keybcs2" // CharsetMacCE 是用於資料庫表格的 `macce` 字符集。 CharsetMacCE CharsetType = "macce" // CharsetMacRoman 是用於資料庫表格的 `macroman` 字符集。 CharsetMacRoman CharsetType = "macroman" // CharsetCP852 是用於資料庫表格的 `cp852` 字符集。 CharsetCP852 CharsetType = "cp852" // CharsetLatin7 是用於資料庫表格的 `latin7` 字符集。 CharsetLatin7 CharsetType = "latin7" // CharsetUTF8MB4 是用於資料庫表格的 `utf8mb4` 字符集。 CharsetUTF8MB4 CharsetType = "utf8mb4" // CharsetCP1251 是用於資料庫表格的 `cp1251` 字符集。 CharsetCP1251 CharsetType = "cp1251" // CharsetUTF16 是用於資料庫表格的 `utf16` 字符集。 CharsetUTF16 CharsetType = "utf16" // CharsetCP1256 是用於資料庫表格的 `cp1256` 字符集。 CharsetCP1256 CharsetType = "cp1256" // CharsetCP1257 是用於資料庫表格的 `cp1257` 字符集。 CharsetCP1257 CharsetType = "cp1257" // CharsetUTF32 是用於資料庫表格的 `utf32` 字符集。 CharsetUTF32 CharsetType = "utf32" // CharsetBinary 是用於資料庫表格的 `binary` 字符集。 CharsetBinary CharsetType = "binary" // CharsetGEOSTD8 是用於資料庫表格的 `geostd8` 字符集。 CharsetGEOSTD8 CharsetType = "geostd8" // CharsetCP932 是用於資料庫表格的 `cp932` 字符集。 CharsetCP932 CharsetType = "cp932" // CharsetEUCJPMS 是用於資料庫表格的 `eucjpms` 字符集。 CharsetEUCJPMS CharsetType = "eucjpms" )
type CollationType ¶
type CollationType string
CollationType 是資料表的字符校對格式。
const ( // CollationBig5 是用於資料庫表格的 `big5_chinese_ci` 字符校對格式。 CollationBig5 CollationType = "big5_chinese_ci" // CollationDEC8 是用於資料庫表格的 `dec8_swedish_ci` 字符校對格式。 CollationDEC8 CollationType = "dec8_swedish_ci" // CollationCP850 是用於資料庫表格的 `cp850_general_ci` 字符校對格式。 CollationCP850 CollationType = "cp850_general_ci" // CollationHP8 是用於資料庫表格的 `hp8_english_ci` 字符校對格式。 CollationHP8 CollationType = "hp8_english_ci" // CollationKOI8R 是用於資料庫表格的 `koi8r_general_ci` 字符校對格式。 CollationKOI8R CollationType = "koi8r_general_ci" // CollationLatin1 是用於資料庫表格的 `latin1_swedish_ci` 字符校對格式。 CollationLatin1 CollationType = "latin1_swedish_ci" // CollationLatin2 是用於資料庫表格的 `latin2_general_ci` 字符校對格式。 CollationLatin2 CollationType = "latin2_general_ci" // CollationSwe7 是用於資料庫表格的 `swe7_swedish_ci` 字符校對格式。 CollationSwe7 CollationType = "swe7_swedish_ci" // CollationASCII 是用於資料庫表格的 `ascii_general_ci` 字符校對格式。 CollationASCII CollationType = "ascii_general_ci" // CollationUJIS 是用於資料庫表格的 `ujis_japanese_ci` 字符校對格式。 CollationUJIS CollationType = "ujis_japanese_ci" // CollationSJIS 是用於資料庫表格的 `sjis_japanese_ci` 字符校對格式。 CollationSJIS CollationType = "sjis_japanese_ci" // CollationHebrew 是用於資料庫表格的 `hebrew_general_ci` 字符校對格式。 CollationHebrew CollationType = "hebrew_general_ci" // CollationTIS620 是用於資料庫表格的 `tis620_thai_ci` 字符校對格式。 CollationTIS620 CollationType = "tis620_thai_ci" // CollationEUCKR 是用於資料庫表格的 `euckr_korean_ci` 字符校對格式。 CollationEUCKR CollationType = "euckr_korean_ci" // CollationKOI8U 是用於資料庫表格的 `koi8u_general_ci` 字符校對格式。 CollationKOI8U CollationType = "koi8u_general_ci" // CollationGB2312 是用於資料庫表格的 `gb2312_chinese_ci` 字符校對格式。 CollationGB2312 CollationType = "gb2312_chinese_ci" // CollationGreek 是用於資料庫表格的 `greek_general_ci` 字符校對格式。 CollationGreek CollationType = "greek_general_ci" // CollationCP1250 是用於資料庫表格的 `cp1250_general_ci` 字符校對格式。 CollationCP1250 CollationType = "cp1250_general_ci" // CollationGBK 是用於資料庫表格的 `gbk_chinese_ci` 字符校對格式。 CollationGBK CollationType = "gbk_chinese_ci" // CollationLatin5 是用於資料庫表格的 `latin5_turkish_ci` 字符校對格式。 CollationLatin5 CollationType = "latin5_turkish_ci" // CollationARMSCII8 是用於資料庫表格的 `armscii8_general_ci` 字符校對格式。 CollationARMSCII8 CollationType = "armscii8_general_ci" // CollationUTF8 是用於資料庫表格的 `utf8_general_ci` 字符校對格式。 CollationUTF8 CollationType = "utf8_general_ci" // CollationUCS2 是用於資料庫表格的 `ucs2_general_ci` 字符校對格式。 CollationUCS2 CollationType = "ucs2_general_ci" // CollationCP866 是用於資料庫表格的 `cp866_general_ci` 字符校對格式。 CollationCP866 CollationType = "cp866_general_ci" // CollationKeybcs2 是用於資料庫表格的 `keybcs2_general_ci` 字符校對格式。 CollationKeybcs2 CollationType = "keybcs2_general_ci" // CollationMacCE 是用於資料庫表格的 `macce_general_ci` 字符校對格式。 CollationMacCE CollationType = "macce_general_ci" // CollationMacRoman 是用於資料庫表格的 `macroman_general_ci` 字符校對格式。 CollationMacRoman CollationType = "macroman_general_ci" // CollationCP852 是用於資料庫表格的 `cp852_general_ci` 字符校對格式。 CollationCP852 CollationType = "cp852_general_ci" // CollationLatin7 是用於資料庫表格的 `latin7_general_ci` 字符校對格式。 CollationLatin7 CollationType = "latin7_general_ci" // CollationUTF8MB4 是用於資料庫表格的 `utf8mb4_general_ci` 字符校對格式。 CollationUTF8MB4 CollationType = "utf8mb4_general_ci" // CollationCP1251 是用於資料庫表格的 `cp1251_general_ci` 字符校對格式。 CollationCP1251 CollationType = "cp1251_general_ci" // CollationUTF16 是用於資料庫表格的 `utf16_general_ci` 字符校對格式。 CollationUTF16 CollationType = "utf16_general_ci" // CollationCP1256 是用於資料庫表格的 `cp1256_general_ci` 字符校對格式。 CollationCP1256 CollationType = "cp1256_general_ci" // CollationCP1257 是用於資料庫表格的 `cp1257_general_ci` 字符校對格式。 CollationCP1257 CollationType = "cp1257_general_ci" // CollationUTF32 是用於資料庫表格的 `utf32_general_ci` 字符校對格式。 CollationUTF32 CollationType = "utf32_general_ci" // CollationBinary 是用於資料庫表格的 `binary` 字符校對格式。 CollationBinary CollationType = "binary" // CollationGEOSTD8 是用於資料庫表格的 `geostd8_general_ci` 字符校對格式。 CollationGEOSTD8 CollationType = "geostd8_general_ci" // CollationCP932 是用於資料庫表格的 `cp932_japanese_ci` 字符校對格式。 CollationCP932 CollationType = "cp932_japanese_ci" // CollationEUCJPMS 是用於資料庫表格的 `eucjpms_japanese_ci` 字符校對格式。 CollationEUCJPMS CollationType = "eucjpms_japanese_ci" )
type EngineType ¶
type EngineType string
EngineType 是資料表的引擎格式。
const ( // EngineInnoDB 是用於資料庫表格的 `InnoDB` 引擎格式。 EngineInnoDB EngineType = "innodb" // EngineMyISAM 是用於資料庫表格的 `MyISAM` 引擎格式。 EngineMyISAM EngineType = "myisam" )
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function 重現了一個像 `SHA(?)` 或 `NOW()` 的資料庫函式。
type Migration ¶
type Migration struct { // LasyQuery 是最後一次所執行的 SQL 指令。 LastQuery string // contains filtered or unexported fields }
Migration 是一個資料庫表格的遷移系統。
func (*Migration) AutoIncrement ¶
AutoIncrement 會將最後一個欄位設置為自動遞增,這僅能用於正整數欄位上。
func (*Migration) Charset ¶
func (m *Migration) Charset(charset CharsetType) *Migration
Charset 會設置資料表格的字符集。
func (*Migration) Collation ¶
func (m *Migration) Collation(collation CollationType) *Migration
Collation 會設置資料表格的字符校對格式。
func (*Migration) DropIfExists ¶
DropIfExists 會移除指定的資料表格,若指定的資料表格存在的話。
func (*Migration) Engine ¶
func (m *Migration) Engine(engine EngineType) *Migration
Engine 能夠設置資料表的引擎種類。
func (*Migration) Foreign ¶
Foreign 會將最後一個欄位設置為外鍵,或者是建立一個匿名/命名群組。 欲將最後一個欄位設置為外鍵欄位可以這麼做:
Columns("id").Foreign("users.id")
欲建立一個匿名的外鍵群組則是像這樣:
.Foreign([]string{"id", "username"}, []string{"users.id", "users.username"})
而一個命名的外鍵群組,第一個參數則是群組的名稱,其他參數與匿名群組無異。
.Foreign("fk_group", []string{"id", "username"}, []string{"users.id", "users.username"})
func (*Migration) Index ¶
Index 會在沒有參數的情況下將某個欄位設定為索引。
.Column("id").Index()
當傳入的參數是一個字串切片時,會將這些欄位名稱作為索引群組。
.Index([]string{"id", "username"})
當第一個參數是字串,第二個則是字串切片時則會建立一個命名的索引群組。
.Index("ik_group", []string{"id", "username"})
func (*Migration) MediumBlob ¶
MediumBlob 會將最後一個欲建立的欄位資料型態設置為 `mediumblob`。
func (*Migration) MediumText ¶
MediumText 會將最後一個欲建立的欄位資料型態設置為 `mediumtext`。
func (*Migration) Primary ¶
Primary 會在沒有參數的情況下將某個欄位設定為主鍵。
.Column("id").Primary()
當傳入的參數是一個字串切片時,會將這些欄位名稱作為主鍵群組。
.Primary([]string{"id", "username"})
當第一個參數是字串,第二個則是字串切片時則會建立一個命名的主鍵群組。
.Primary("pk_group", []string{"id", "username"})
func (*Migration) Unique ¶
Unique 會在沒有參數的情況下將某個欄位設定為不重覆鍵。
.Column("id").Unique()
當傳入的參數是一個字串切片時,會將這些欄位名稱作為不重覆鍵群組。
.Unique([]string{"id", "username"})
當第一個參數是字串,第二個則是字串切片時則會建立一個命名的不重覆鍵群組。
.Unique("uk_group", []string{"id", "username"})
type SubQuery ¶
type SubQuery struct { // PageLimit 限制了一頁僅能有幾筆資料。 PageLimit int // contains filtered or unexported fields }
SubQuery 是單個子指令,任何的變更都會回傳一份複製子指令來避免多個 Goroutine 編輯同個子指令指標建構體。
func (*SubQuery) JoinOrWhere ¶
JoinOrWhere 能夠建立一個基於 `WHERE OR` 的條件式給某個指定的插入資料表格。
func (*SubQuery) NaturalJoin ¶
NaturalJoin 會自然插入一個資料表格。
func (*SubQuery) Paginate ¶
Paginate 基本上和 `Get` 取得函式無異,但此函式能夠自動依照分頁數來推算該從哪裡繼續取得資料。 使用時須先確定是否有指定 `PageLimit`(預設為:20),這樣才能限制一頁有多少筆資料。
func (*SubQuery) RawQuery ¶
RawQuery 會接收傳入的變數來執行傳入的 SQL 執行語句,變數可以在語句中以 `?`(Prepared Statements)使用來避免 SQL 注入攻擊。 這會將多筆資料映射到本地的建構體切片、陣列上。
type Timestamp ¶
type Timestamp struct {
// contains filtered or unexported fields
}
Timestamp 是一個資料庫的時間戳輔助函式。