github.com/kotovmak/go-admin@v1.1.1/modules/db/dialect/common.go (about) 1 package dialect 2 3 import "fmt" 4 5 type commonDialect struct { 6 delimiter string 7 delimiter2 string 8 } 9 10 func (c commonDialect) Insert(comp *SQLComponent) string { 11 comp.prepareInsert(c.delimiter, c.delimiter2) 12 return comp.Statement 13 } 14 15 func (c commonDialect) Delete(comp *SQLComponent) string { 16 comp.Statement = "delete from " + c.WrapTableName(comp) + comp.getWheres(c.delimiter, c.delimiter2) 17 return comp.Statement 18 } 19 20 func (c commonDialect) Update(comp *SQLComponent) string { 21 comp.prepareUpdate(c.delimiter, c.delimiter2) 22 return comp.Statement 23 } 24 25 func (c commonDialect) Count(comp *SQLComponent) string { 26 comp.prepareUpdate(c.delimiter, c.delimiter2) 27 return comp.Statement 28 } 29 30 func (c commonDialect) Select(comp *SQLComponent) string { 31 comp.Statement = "select " + comp.getFields(c.delimiter, c.delimiter2) + " from " + c.WrapTableName(comp) + comp.getJoins(c.delimiter, c.delimiter2) + 32 comp.getWheres(c.delimiter, c.delimiter2) + comp.getGroupBy() + comp.getOrderBy() + comp.getLimit() + comp.getOffset() 33 return comp.Statement 34 } 35 36 func (c commonDialect) ShowColumns(table string) string { 37 return fmt.Sprintf("select * from information_schema.columns where table_name = '%s'", table) 38 } 39 40 func (c commonDialect) GetName() string { 41 return "common" 42 } 43 44 func (c commonDialect) WrapTableName(comp *SQLComponent) string { 45 return c.delimiter + comp.TableName + c.delimiter2 46 } 47 48 func (c commonDialect) ShowTables() string { 49 return "show tables" 50 } 51 52 func (c commonDialect) GetDelimiter() string { 53 return c.delimiter 54 } 55 56 func (c commonDialect) GetDelimiter2() string { 57 return c.delimiter2 58 } 59 60 func (c commonDialect) GetDelimiters() []string { 61 return []string{c.delimiter, c.delimiter2} 62 }