2014-04-25 05:11:32 -04:00
|
|
|
// +build cgo
|
2014-01-31 05:16:42 -05:00
|
|
|
|
2013-12-19 00:14:16 -05:00
|
|
|
package graphdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"os"
|
2014-05-30 20:44:00 -04:00
|
|
|
|
|
|
|
_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
|
2013-12-19 00:14:16 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewSqliteConn(root string) (*Database, error) {
|
|
|
|
initDatabase := false
|
2014-05-30 20:44:00 -04:00
|
|
|
|
|
|
|
stat, err := os.Stat(root)
|
|
|
|
if err != nil {
|
2013-12-19 00:14:16 -05:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
initDatabase = true
|
|
|
|
} else {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 20:44:00 -04:00
|
|
|
|
|
|
|
if stat != nil && stat.Size() == 0 {
|
|
|
|
initDatabase = true
|
|
|
|
}
|
|
|
|
|
2013-12-19 00:14:16 -05:00
|
|
|
conn, err := sql.Open("sqlite3", root)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-05-30 20:44:00 -04:00
|
|
|
|
2013-12-19 00:14:16 -05:00
|
|
|
return NewDatabase(conn, initDatabase)
|
|
|
|
}
|