-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdialect_sqlite.go
48 lines (34 loc) · 1.41 KB
/
dialect_sqlite.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package schema
import (
"database/sql"
)
const sqliteAllColumns = `SELECT * FROM %s LIMIT 0`
const sqliteTableNames = `SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name`
const sqliteViewNames = `SELECT name FROM sqlite_master WHERE type = 'view' ORDER BY name`
const sqlitePrimaryKey = `SELECT name FROM pragma_table_info(?) WHERE pk > 0 ORDER BY pk`
type sqliteDialect struct{}
func (sqliteDialect) escapeIdent(ident string) string {
// "tablename"
return escapeWithDoubleQuotes(ident)
}
func (sqliteDialect) PrimaryKey(db *sql.DB, name string) ([]string, error) {
return fetchNames(db, sqlitePrimaryKey, name)
}
func (d sqliteDialect) Table(db *sql.DB, name string) ([]*sql.ColumnType, error) {
return fetchColumnTypes(db, sqliteAllColumns, name, d.escapeIdent)
}
func (sqliteDialect) TableNames(db *sql.DB) ([]string, error) {
return fetchNames(db, sqliteTableNames, "")
}
func (d sqliteDialect) Tables(db *sql.DB) (map[string][]*sql.ColumnType, error) {
return fetchColumnTypesAll(db, d.TableNames, d.Table)
}
func (d sqliteDialect) View(db *sql.DB, name string) ([]*sql.ColumnType, error) {
return fetchColumnTypes(db, sqliteAllColumns, name, d.escapeIdent)
}
func (sqliteDialect) ViewNames(db *sql.DB) ([]string, error) {
return fetchNames(db, sqliteViewNames, "")
}
func (d sqliteDialect) Views(db *sql.DB) (map[string][]*sql.ColumnType, error) {
return fetchColumnTypesAll(db, d.ViewNames, d.View)
}