graphdb: initialize the database semi-idempotently on every connection.
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
8c02df4c6c
commit
12efe03ef0
3 changed files with 45 additions and 51 deletions
|
@ -4,31 +4,15 @@ package graphdb
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
|
||||
_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
|
||||
)
|
||||
|
||||
func NewSqliteConn(root string) (*Database, error) {
|
||||
initDatabase := false
|
||||
|
||||
stat, err := os.Stat(root)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
initDatabase = true
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if stat != nil && stat.Size() == 0 {
|
||||
initDatabase = true
|
||||
}
|
||||
|
||||
conn, err := sql.Open("sqlite3", root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewDatabase(conn, initDatabase)
|
||||
return NewDatabase(conn)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue