github.com/gogf/gf@v1.16.9/database/gdb/gdb_core_utility.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 // 7 8 package gdb 9 10 // MasterLink acts like function Master but with additional `schema` parameter specifying 11 // the schema for the connection. It is defined for internal usage. 12 // Also see Master. 13 func (c *Core) MasterLink(schema ...string) (Link, error) { 14 db, err := c.db.Master(schema...) 15 if err != nil { 16 return nil, err 17 } 18 return &dbLink{db}, nil 19 } 20 21 // SlaveLink acts like function Slave but with additional `schema` parameter specifying 22 // the schema for the connection. It is defined for internal usage. 23 // Also see Slave. 24 func (c *Core) SlaveLink(schema ...string) (Link, error) { 25 db, err := c.db.Slave(schema...) 26 if err != nil { 27 return nil, err 28 } 29 return &dbLink{db}, nil 30 } 31 32 // QuoteWord checks given string `s` a word, if true quotes it with security chars of the database 33 // and returns the quoted string; or else return `s` without any change. 34 // The meaning of a `word` can be considered as a column name. 35 func (c *Core) QuoteWord(s string) string { 36 charLeft, charRight := c.db.GetChars() 37 return doQuoteWord(s, charLeft, charRight) 38 } 39 40 // QuoteString quotes string with quote chars. Strings like: 41 // "user", "user u", "user,user_detail", "user u, user_detail ut", "u.id asc". 42 // The meaning of a `string` can be considered as part of a statement string including columns. 43 func (c *Core) QuoteString(s string) string { 44 charLeft, charRight := c.db.GetChars() 45 return doQuoteString(s, charLeft, charRight) 46 } 47 48 // QuotePrefixTableName adds prefix string and quotes chars for the table. 49 // It handles table string like: 50 // "user", "user u", 51 // "user,user_detail", 52 // "user u, user_detail ut", 53 // "user as u, user_detail as ut". 54 // 55 // Note that, this will automatically checks the table prefix whether already added, 56 // if true it does nothing to the table name, or else adds the prefix to the table name. 57 func (c *Core) QuotePrefixTableName(table string) string { 58 charLeft, charRight := c.db.GetChars() 59 return doHandleTableName(table, c.db.GetPrefix(), charLeft, charRight) 60 } 61 62 // GetChars returns the security char for current database. 63 // It does nothing in default. 64 func (c *Core) GetChars() (charLeft string, charRight string) { 65 return "", "" 66 } 67 68 // Tables retrieves and returns the tables of current schema. 69 // It's mainly used in cli tool chain for automatically generating the models. 70 // 71 // It does nothing in default. 72 func (c *Core) Tables(schema ...string) (tables []string, err error) { 73 return 74 } 75 76 // TableFields retrieves and returns the fields information of specified table of current schema. 77 // 78 // Note that it returns a map containing the field name and its corresponding fields. 79 // As a map is unsorted, the TableField struct has a "Index" field marks its sequence in the fields. 80 // 81 // It's using cache feature to enhance the performance, which is never expired util the process restarts. 82 // 83 // It does nothing in default. 84 func (c *Core) TableFields(table string, schema ...string) (fields map[string]*TableField, err error) { 85 return 86 }