update docs for sqlite package

This commit is contained in:
Adam Babik 2019-07-17 12:12:02 +02:00
parent 7623131be4
commit 35e60767b7
No known key found for this signature in database
GPG Key ID: ED02515A1FC0D1B4
2 changed files with 15 additions and 0 deletions

View File

@ -22,15 +22,20 @@ const defaultKdfIterationsNumber = 64000 // nolint: deadcode,varcheck,unused
// https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA // https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA
const reducedKdfIterationsNumber = 3200 const reducedKdfIterationsNumber = 3200
// MigrationConfig is a struct that allows to define bindata migrations.
type MigrationConfig struct { type MigrationConfig struct {
AssetNames []string AssetNames []string
AssetGetter func(name string) ([]byte, error) AssetGetter func(name string) ([]byte, error)
} }
// Open opens or initializes a new database for a given file path.
// MigrationConfig is optional but if provided migrations are applied automatically.
func Open(path, key string, mc MigrationConfig) (*sql.DB, error) { func Open(path, key string, mc MigrationConfig) (*sql.DB, error) {
return open(path, key, reducedKdfIterationsNumber, mc) return open(path, key, reducedKdfIterationsNumber, mc)
} }
// OpenWithIter allows to open a new database with a custom number of kdf iterations.
// Higher kdf iterations number makes it slower to open the database.
func OpenWithIter(path, key string, kdfIter int, mc MigrationConfig) (*sql.DB, error) { func OpenWithIter(path, key string, kdfIter int, mc MigrationConfig) (*sql.DB, error) {
return open(path, key, kdfIter, mc) return open(path, key, kdfIter, mc)
} }
@ -79,6 +84,9 @@ func open(path string, key string, kdfIter int, mc MigrationConfig) (*sql.DB, er
return db, nil return db, nil
} }
// ApplyMigrations allows to apply bindata migrations on the current *sql.DB.
// `assetNames` is a list of assets with migrations and `assetGetter` is responsible
// for returning the content of the asset with a given name.
func ApplyMigrations(db *sql.DB, assetNames []string, assetGetter func(name string) ([]byte, error)) error { func ApplyMigrations(db *sql.DB, assetNames []string, assetGetter func(name string) ([]byte, error)) error {
resources := bindata.Resource( resources := bindata.Resource(
assetNames, assetNames,

7
sqlite/doc.go Normal file
View File

@ -0,0 +1,7 @@
// Package sqlite is responsible for creation of encrypted sqlite3 database using sqlcipher driver.
// It is optimized for mobile usage as well.
//
// sqlite package also provides a capability to apply bindata migration.
// You can keep your migrations close to your business logic and use this package
// to create an encrypted sqlite3 database and then apply the migrations easily.
package sqlite