1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/graphdb/conn_sqlite3.go
Michael Crosby b0ea389c69 Init database if empty file
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-05-30 17:44:00 -07:00

34 lines
521 B
Go

// +build cgo
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)
}