forked from adlio/schema
/
dialect.go
33 lines (28 loc) · 980 Bytes
/
dialect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package schema
import "database/sql"
// Dialect defines the interface for a database dialect.
// All interface functions take the customized table name
// as input and return a SQL statement with placeholders
// appropriate to the database.
//
type Dialect interface {
QuotedTableName(schemaName, tableName string) string
CreateSQL(tableName string) string
SelectSQL(tableName string) string
InsertSQL(tableName string) string
}
// Locking is achieved by implementing at least one of the
// Locker interfaces. If the database natively supports
// locking through SQL, the SQLLocker is simpler. If neither
// interface is present a panic will occur.
// Locker defines an interface that implements locking.
type Locker interface {
Lock(db *sql.DB) error
Unlock(db *sql.DB) error
}
// SQLLocker defines an interface that implements locking
// using a single SQL statement.
type SQLLocker interface {
LockSQL(tableName string) string
UnlockSQL(tableName string) string
}