forked from chuckpreslar/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex.go
More file actions
68 lines (54 loc) · 1.6 KB
/
codex.go
File metadata and controls
68 lines (54 loc) · 1.6 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Package codex provides a Relational Algebra for PostgreSQL and MySQL. Based on Arel (Ruby on Rails).
package codex
import (
"regexp"
)
type adapter uint8
const (
MYSQL adapter = iota + 1
POSTGRES
)
var VALID_COL_NAME_PATTERN *regexp.Regexp
var VALID_TABLE_NAME_PATTERN *regexp.Regexp
func init() {
var err error
VALID_COL_NAME_PATTERN, err = regexp.Compile(`(?i)^[a-z][a-z0-9_\$]*$`)
if err != nil {
panic(err)
}
VALID_TABLE_NAME_PATTERN = VALID_COL_NAME_PATTERN
}
// ToggleDebugMode toggles debugger variable for managers package.
func ToggleDebugMode() {
DEBUG = !DEBUG
}
type DbDialect func(string) *AttributeNode
func (db DbDialect) Table(name string) *TableNode {
return db(name).Table
}
func Dialect(adapter adapter) DbDialect {
return func(tableName string) *AttributeNode {
table := Table(tableName)
table.Adapter = adapter
return Attribute(tableName, table)
}
}
// // deprecated
// // Table returns an Accessor from the managers package for
// // generating SQL to interact with existing tables.
// func Table(tableName string) Accessor {
// table := Table(tableName)
// return func(colName interface{}) *AttributeNode {
// if _, ok := colName.(string); ok {
// return Attribute(Column(colName), table)
// }
// return Attribute(colName, table)
// }
// }
// Scoper enables scoping support for SelectManager, UpdateManager, DeleteManager
type Scoper interface {
// Scope wraps Where method and omits the return value so Scope() signature remains generic
Scope(expr interface{}, args ...interface{})
}
// ScopeFunc is implemented by DB layer 'models'
type ScopeFunc func(Scoper)