Documentation ¶
Index ¶
- Constants
- Variables
- func Equals(key Key, r Record) bool
- func Search(key Key, r Record) bool
- type Database
- func (db *Database) Close() error
- func (db *Database) Index(name string) (*Index, error)
- func (db *Database) Indexes() ([]string, error)
- func (db *Database) Info() (string, error)
- func (db *Database) NonRowidTable(name string) (*Index, error)
- func (db *Database) RLock() error
- func (db *Database) RUnlock() error
- func (db *Database) Table(name string) (*Table, error)
- func (db *Database) Tables() ([]string, error)
- type Index
- type Key
- type KeyCol
- type Record
- type RecordCB
- type Table
- type TableScanCB
Constants ¶
const ( // CachePages is the number of pages to keep in memory. Default size per // page is 4K (1K on older databases). CachePages = 100 )
Variables ¶
var ( // Various error messages returned when the database is corrupted ErrInvalidMagic = errors.New("invalid magic number") ErrInvalidPageSize = errors.New("invalid page size") ErrReservedSpace = errors.New("unsupported database (encrypted?)") ErrCorrupted = errors.New("database corrupted") ErrInvalidDef = errors.New("invalid object definition") ErrRecursion = errors.New("tree is too deep") // Various error messages returned when the database uses features sqlittle // doesn't support. ErrIncompatible = errors.New("incompatible database version") ErrEncoding = errors.New("unsupported encoding") // Database is in WAL journal mode, which we don't support. You need to // convert the database to journal mode. ErrWAL = errors.New("WAL journal mode is unsupported") // There is a stale `-journal` file present with an unfinished transaction. // Open the database in sqlite3 to repair the database. ErrHotJournal = errors.New("crashed transaction present") ErrNoSuchTable = errors.New("no such table") ErrNoSuchIndex = errors.New("no such index") )
var CollateFuncs = map[string]func(string, string) int{ "binary": strings.Compare, "rtrim": func(a, b string) int { return strings.Compare( strings.TrimRight(a, " \t\r\n"), strings.TrimRight(b, " \t\r\n"), ) }, "nocase": func(a, b string) int { lc := func(r rune) rune { if r >= 'A' && r <= 'Z' { return rune(strings.ToLower(string(r))[0]) } return r } return strings.Compare( strings.Map(lc, a), strings.Map(lc, b), ) }, }
available collate functions
var DefaultCollate = "binary"
Functions ¶
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func OpenFile ¶
OpenFile opens a .sqlite file. This is the main entry point. Use database.Close() when done.
func (*Database) Index ¶
Index opens the named index. Will return ErrNoSuchIndex when the index isn't there (or isn't an index). Index pointer is always valid if err == nil.
Indexes work for normal and WITHOUT ROWID tables. The columns the callback gets depends on the type of table.
func (*Database) Indexes ¶
Indexes lists all index names.
func (*Database) Info ¶
Info gives some debugging info about the open database
func (*Database) NonRowidTable ¶
NonRowidTable open a `WITHOUT ROWID` table. It's implemented with an Index.
func (*Database) RLock ¶
Lock database for reading. Blocks. Don't nest RLock() calls.
func (*Database) RUnlock ¶
Unlock a read lock. Use a single RUnlock() for every RLock().
func (*Database) Table ¶
Table opens the named table. Will return ErrNoSuchTable when the table isn't there (or isn't a table). Table pointer is always valid if err == nil. See also NonRowidTable() for `WITHOUT ROWID` tables.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is either an index, or the table for a non-rowid table
func (*Index) Scan ¶
Scan calls cb() for every row in the index. These will be called in the index order. The callback gets the record as stored in the index. For indexes on a non-WITHOUT ROWID table the last value will be the rowid (see ChompRowid()). For a WITHOUT ROWID table the columns depend on your table structure. If the callback returns true (done) the scan will be stopped.
func (*Index) ScanEq ¶
Scan all record matching key
func (*Index) ScanMin ¶
ScanMin calls cb() for every row in the index, starting from the first record where key is true.
If the callback returns true (done) the scan will be stopped. All comments from Index.Scan are valid here as well.
type KeyCol ¶
type Record ¶
type Record []interface{}
Record is a row in the database. It can only have fields of these types: nil, int64, float64, string, []byte
type RecordCB ¶
RecordCB is passed to Index.Scan(), Index.ScanMin(), and Table.ScanWithoutRowid. It should return true when the scan should be stopped.
For index scans: The callback gets the raw values as stored in the index. For a normal index the last value is the rowid value (see ChompRowid()). For a WITHOUT ROWID it depends on the table which rows there are.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func (*Table) Rowid ¶
Rowid finds a single row by rowid. Will return nil if it isn't found. The rowid is an internal id, but if you have an `integer primary key` column that should be the same. See Table.Scan comments about the Record
func (*Table) Scan ¶
func (t *Table) Scan(cb TableScanCB) error
Scan calls cb() for every row in the table. Will be called in 'database order'. The record is given as sqlite stores it; this means:
- float64 columns might be stored as int64
- after an alter table which adds columns a row might miss the new columns
- an "integer primary key" column will be always be nil, and the rowid is the value
If the callback returns true (done) the scan will be stopped.