-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdorm.go
98 lines (82 loc) · 3.15 KB
/
dorm.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package dorm
import (
"database/sql"
)
// DB handle
type DB struct {
inner *sql.DB
}
// NewDB returns a new DB using the provided `conn`,
// an sql database connection.
// This function is provided for you. You DO NOT need to modify it.
func NewDB(conn *sql.DB) DB {
return DB{inner: conn}
}
// Close closes db's database connection.
// This function is provided for you. You DO NOT need to modify it.
func (db *DB) Close() error {
return db.inner.Close()
}
// ColumnNames analyzes a struct, v, and returns a list of strings,
// one for each of the public fields of v.
// The i'th string returned should be equal to the name of the i'th
// public field of v, converted to underscore_case.
// Refer to the specification of underscore_case, below.
// Example usage:
// type MyStruct struct {
// ID int64
// UserName string
// }
// ColumnNames(&MyStruct{}) ==> []string{"id", "user_name"}
func ColumnNames(v interface{}) []string {
return []string{}
}
// TableName analyzes a struct, v, and returns a single string, equal
// to the name of that struct's type, converted to underscore_case.
// Refer to the specification of underscore_case, below.
// Example usage:
// type MyStruct struct {
// ...
// }
// TableName(&MyStruct{}) ==> "my_struct"
func TableName(result interface{}) string {
return ""
}
// Find queries a database for all rows in a given table,
// and stores all matching rows in the slice provided as an argument.
// The argument `result` will be a pointer to an empty slice of models. // To be explicit, it will have type: *[]MyStruct,
// where MyStruct is any arbitrary struct subject to the restrictions
// discussed later in this document.
// You may assume the slice referenced by `result` is empty.
// Example usage to find all UserComment entries in the database:
// type UserComment struct = { ... }
// result := []UserComment{}
// db.Find(&result)
func (db *DB) Find(result interface{}) {
}
// First queries a database for the first row in a table,
// and stores the matching row in the struct provided as an argument.
// If no such entry exists, First returns false; else it returns true.
// The argument `result` will be a pointer to a model.
// To be explicit, it will have type: *MyStruct,
// where MyStruct is any arbitrary struct subject to the restrictions
// discussed later in this document.
// Example usage to find the first UserComment entry in the database:
// type UserComment struct = { ... }
// result := &UserComment{}
// ok := db.First(result)
// with the argument), otherwise return true.
func (db *DB) First(result interface{}) bool {
return false
}
// Create adds the specified model to the appropriate database table.
// The table for the model *must* already exist, and Create() should
// panic if it does not.
// Optionally, at most one of the fields of the provided `model`
// might be annotated with the tag `dorm:"primary_key"`. If such a
// field exists, Create() should ignore the provided value of that
// field, overwriting it with the auto-incrementing row ID.
// This ID is given by the value of last_inserted_rowid(),
// returned from the underlying sql database.
func (db *DB) Create(model interface{}) {
}