sqlite

package
v0.179.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The reduced number of kdf iterations (for performance reasons) which is
	// used as the default value
	// https://github.com/status-im/status-go/pull/1343
	// https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA
	ReducedKDFIterationsNumber = 3200

	// WALMode for sqlite.
	WALMode          = "wal"
	InMemoryPath     = ":memory:"
	V4CipherPageSize = 8192
	V3CipherPageSize = 1024
)

Variables

This section is empty.

Functions

func BigIntToClampedInt64 added in v0.157.2

func BigIntToClampedInt64(val *big.Int) *int64

func BigIntToPadded128BitsStr added in v0.157.2

func BigIntToPadded128BitsStr(val *big.Int) *string

BigIntToPadded128BitsStr converts a big.Int to a string, padding it with 0 to account for 128 bits size Returns nil if input val is nil This should work to sort and compare big.Ints values in SQLite

func ChangeEncryptionKey added in v0.80.2

func ChangeEncryptionKey(path string, key string, kdfIterationsNumber int, newKey string, onStart func(), onEnd func()) error

func DecryptDB added in v0.69.0

func DecryptDB(oldPath string, newPath string, key string, kdfIterationsNumber int) error

DecryptDB completely removes the encryption from the db

func EncryptDB added in v0.69.0

func EncryptDB(unencryptedPath string, encryptedPath string, key string, kdfIterationsNumber int, onStart func(), onEnd func()) error

EncryptDB takes a plaintext database and adds encryption

func ExportDB added in v0.158.0

func ExportDB(encryptedPath string, key string, kdfIterationsNumber int, newPath string, newKey string, onStart func(), onEnd func()) error

Export takes an encrypted database and re-encrypts it in a new file, with a new key

func GetLastMigrationVersion added in v0.157.2

func GetLastMigrationVersion(db *sql.DB) (version uint, migrationTableExists bool, err error)

GetLastMigrationVersion returns the last migration version stored in the migration table. Returns 0 for version in case migrationTableExists is true

func Int64ToPadded128BitsStr added in v0.159.2

func Int64ToPadded128BitsStr(val int64) *string

func Migrate

func Migrate(db *sql.DB, resources *bindata.AssetSource, customSteps []*PostStep, untilVersion *uint) error

Migrate database with option to augment the migration steps with additional processing using the customSteps parameter. For each PostStep entry in customSteps the CustomMigration will be called after the migration step with the matching Version number has been executed. If the CustomMigration returns an error, the migration process is aborted. In case the custom step failures the migrations are run down to RollBackVersion if > 0.

The recommended way to create a custom migration is by providing empty and versioned run/down sql files as markers. Then running all the SQL code inside the same transaction to transform and commit provides the possibility to completely rollback the migration in case of failure, avoiding to leave the DB in an inconsistent state.

Marker migrations can be created by using PostStep structs with specific Version numbers and a callback function, even when no accompanying SQL migration is needed. This can be used to trigger Go code at specific points during the migration process.

Caution: This mechanism should be used as a last resort. Prefer data migration using SQL migration files whenever possible to ensure consistency and compatibility with standard migration tools.

untilVersion, for testing purposes optional parameter, can be used to limit the migration to a specific version. Pass nil to migrate to the latest available version.

func MigrateV3ToV4 added in v0.158.0

func MigrateV3ToV4(v3Path string, v4Path string, key string, kdfIterationsNumber int, onStart func(), onEnd func()) error

MigrateV3ToV4 migrates database from v3 to v4 format with encryption.

func OpenDB

func OpenDB(path string, key string, kdfIterationsNumber int) (*sql.DB, error)

OpenDB opens encrypted database.

func OpenUnecryptedDB

func OpenUnecryptedDB(path string) (*sql.DB, error)

OpenUnecryptedDB opens database with setting PRAGMA key.

Types

type CustomMigrationFunc added in v0.163.14

type CustomMigrationFunc func(tx *sql.Tx) error

type JSONBlob

type JSONBlob struct {
	Data  interface{}
	Valid bool
}

JSONBlob type for marshaling/unmarshaling inner type to json.

func (*JSONBlob) Scan

func (blob *JSONBlob) Scan(value interface{}) error

Scan implements interface.

func (*JSONBlob) Value

func (blob *JSONBlob) Value() (driver.Value, error)

Value implements interface.

type PostStep added in v0.157.2

type PostStep struct {
	Version         uint
	CustomMigration CustomMigrationFunc
	RollBackVersion uint
}

type StatementCreator added in v0.163.4

type StatementCreator interface {
	Prepare(query string) (*sql.Stmt, error)
}

statementCreator allows to pass transaction or database to use in consumer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL