-
Notifications
You must be signed in to change notification settings - Fork 5
/
basic.go
54 lines (44 loc) · 1.11 KB
/
basic.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
package main
import (
"github.com/quintans/goSQL/db"
trx "github.com/quintans/goSQL/translators"
_ "github.com/go-sql-driver/mysql"
"database/sql"
"fmt"
)
// the entity
type Publisher struct {
Id int64
Version int64
Name string
}
// table description/mapping
var (
PUBLISHER = db.TABLE("PUBLISHER")
PUBLISHER_C_ID = PUBLISHER.KEY("ID") // implicit map to field Id
PUBLISHER_C_VERSION = PUBLISHER.VERSION("VERSION") // implicit map to field Version
PUBLISHER_C_NAME = PUBLISHER.COLUMN("NAME") // implicit map to field Name
)
// the transaction manager
var tm db.ITransactionManager
func main() {
// database configuration
mydb, err := sql.Open("mysql", "root:root@/gosql?parseTime=true")
if err != nil {
fmt.Printf("%+v\n", err)
panic(err)
}
// transaction manager
tm = db.NewTransactionManager(mydb, trx.NewMySQL5Translator())
// get the databse context
store := tm.Store()
// the target entity
var publisher Publisher
// Retrieve
_, err = store.Retrieve(&publisher, 2)
if err != nil {
fmt.Printf("%+v\n", err)
panic(err)
}
fmt.Println(publisher)
}