Example #1
0
File: db.go Project: 0x7cc/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
}
Example #2
0
File: db.go Project: 0x7cc/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
}