mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-07-01 12:08:37 -04:00
Initial commit
This commit is contained in:
32
db.go
Normal file
32
db.go
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"gopkg.in/gorp.v1"
|
||||
"log"
|
||||
)
|
||||
|
||||
var DB *gorp.DbMap = initDB()
|
||||
|
||||
func initDB() *gorp.DbMap {
|
||||
db, err := sql.Open("sqlite3", "file:moneygo.sqlite?cache=shared&mode=rwc")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
|
||||
dbmap.AddTableWithName(User{}, "users").SetKeys(true, "UserId")
|
||||
dbmap.AddTableWithName(Session{}, "sessions").SetKeys(true, "SessionId")
|
||||
dbmap.AddTableWithName(Account{}, "accounts").SetKeys(true, "AccountId")
|
||||
dbmap.AddTableWithName(Security{}, "security").SetKeys(true, "SecurityId")
|
||||
dbmap.AddTableWithName(Transaction{}, "transactions").SetKeys(true, "TransactionId")
|
||||
dbmap.AddTableWithName(Split{}, "splits").SetKeys(true, "SplitId")
|
||||
|
||||
err = dbmap.CreateTablesIfNotExists()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return dbmap
|
||||
}
|
Reference in New Issue
Block a user