status-go/appdatabase/database.go
Shivek Khurana 81171ad9e6
Expose password reset function (#2223)
Handled edge-cases
2021-06-23 14:51:21 +05:30

38 lines
1 KiB
Go

package appdatabase
import (
"database/sql"
"github.com/status-im/status-go/appdatabase/migrations"
"github.com/status-im/status-go/sqlite"
)
// InitializeDB creates db file at a given path and applies migrations.
func InitializeDB(path, password string) (*sql.DB, error) {
db, err := sqlite.OpenDB(path, password)
if err != nil {
return nil, err
}
err = migrations.Migrate(db)
if err != nil {
return nil, err
}
return db, nil
}
// DecryptDatabase creates an unencrypted copy of the database and copies it
// over to the given directory
func DecryptDatabase(oldPath, newPath, password string) error {
return sqlite.DecryptDB(oldPath, newPath, password)
}
// EncryptDatabase creates an encrypted copy of the database and copies it to the
// user path
func EncryptDatabase(oldPath, newPath, password string) error {
return sqlite.EncryptDB(oldPath, newPath, password)
}
func ChangeDatabasePassword(path, password, newPassword string) error {
return sqlite.ChangeEncryptionKey(path, password, newPassword)
}