2014-04-16 15:41:19 +00:00
|
|
|
// +build linux,amd64 freebsd,cgo
|
2014-01-31 10:16:42 +00:00
|
|
|
|
2013-12-23 23:33:06 +00:00
|
|
|
package graphdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
|
|
|
|
"database/sql"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewSqliteConn(root string) (*Database, error) {
|
|
|
|
initDatabase := false
|
|
|
|
if _, err := os.Stat(root); err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
initDatabase = true
|
|
|
|
} else {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conn, err := sql.Open("sqlite3", root)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewDatabase(conn, initDatabase)
|
|
|
|
}
|