示例#1
0
文件: db.go 项目: amrhassan/rsc
// Create creates a new database in the named file.
// The file must not exist.
func Create(name string) (*DB, error) {
	_, err := os.Stat(name)
	if !os.IsNotExist(err) {
		return nil, fmt.Errorf("create %s: already exists", name)
	}

	meta, err := sql.Open("sqlite3", name)
	if err != nil {
		return nil, err
	}
	store := new(dbstore.Storage)
	store.Register(new(Doc))
	store.Register(new(thumb))
	store.Register(new(text))

	if err := store.CreateTables(meta); err != nil {
		return nil, err
	}

	return &DB{meta, store, name}, nil
}
示例#2
0
文件: db.go 项目: amrhassan/rsc
// Open opens the database in the named file.
func Open(name string) (*DB, error) {
	_, err := os.Stat(name)
	if err != nil {
		return nil, err
	}
	meta, err := sql.Open("sqlite3", name)
	if err != nil {
		return nil, err
	}
	store := new(dbstore.Storage)
	store.Register(new(Doc))
	store.Register(new(thumb))
	store.Register(new(text))
	return &DB{meta, store, name}, nil
}