From 35e60767b797cc36e155595b4ec7c329f929b323 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Wed, 17 Jul 2019 12:12:02 +0200 Subject: [PATCH] update docs for sqlite package --- sqlite/db.go | 8 ++++++++ sqlite/doc.go | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 sqlite/doc.go diff --git a/sqlite/db.go b/sqlite/db.go index 7562d3b..00e6075 100644 --- a/sqlite/db.go +++ b/sqlite/db.go @@ -22,15 +22,20 @@ const defaultKdfIterationsNumber = 64000 // nolint: deadcode,varcheck,unused // https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA const reducedKdfIterationsNumber = 3200 +// MigrationConfig is a struct that allows to define bindata migrations. type MigrationConfig struct { AssetNames []string 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) { 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) { 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 } +// 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 { resources := bindata.Resource( assetNames, diff --git a/sqlite/doc.go b/sqlite/doc.go new file mode 100644 index 0000000..dd971be --- /dev/null +++ b/sqlite/doc.go @@ -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