@@ -5,14 +5,32 @@ import (
5
5
"reflect"
6
6
)
7
7
8
+ // The Dialect interface encapsulates behaviors that differ across
9
+ // SQL databases. At present the Dialect is only used by CreateTables()
10
+ // but this could change in the future
8
11
type Dialect interface {
12
+
13
+ // ToSqlType returns the SQL column type to use when creating a
14
+ // table of the given Go Type. maxsize can be used to switch based on
15
+ // size. For example, in MySQL []byte could map to BLOB, MEDIUMBLOB,
16
+ // or LONGBLOB depending on the maxsize
9
17
ToSqlType (val reflect.Type , maxsize int ) string
18
+
19
+ // string to append to primary key column definitions
10
20
AutoIncrStr () string
21
+
22
+ // string to append to "create table" statement for vendor specific
23
+ // table attributes
11
24
CreateTableSuffix () string
12
25
}
13
26
27
+ // Implementation of Dialect for MySQL databases.
14
28
type MySQLDialect struct {
29
+
30
+ // Engine is the storage engine to use "InnoDB" vs "MyISAM" for example
15
31
Engine string
32
+
33
+ // Encoding is the character encoding to use for created tables
16
34
Encoding string
17
35
}
18
36
@@ -30,10 +48,12 @@ func (m MySQLDialect) ToSqlType(val reflect.Type, maxsize int) string {
30
48
return fmt .Sprintf ("varchar(%d)" , maxsize )
31
49
}
32
50
51
+ // Returns auto_increment
33
52
func (m MySQLDialect ) AutoIncrStr () string {
34
53
return "auto_increment"
35
54
}
36
55
56
+ // Returns engine=%s charset=%s based on values stored on struct
37
57
func (m MySQLDialect ) CreateTableSuffix () string {
38
58
return fmt .Sprintf (" engine=%s charset=%s" , m .Engine , m .Encoding )
39
59
}
0 commit comments