package sqlite3// Backup is an handle to an ongoing online backup operation.//// https://sqlite.org/c3ref/backup.htmltypeBackupstruct { c *Conn handle ptr_t otherc ptr_t}// Backup backs up srcDB on the src connection to the "main" database in dstURI.//// Backup opens the SQLite database file dstURI,// and blocks until the entire backup is complete.// Use [Conn.BackupInit] for incremental backup.//// https://sqlite.org/backup.htmlfunc ( *Conn) (, string) error { , := .BackupInit(, )if != nil {return }defer .Close() _, = .Step(-1)return}// Restore restores dstDB on the dst connection from the "main" database in srcURI.//// Restore opens the SQLite database file srcURI,// and blocks until the entire restore is complete.//// https://sqlite.org/backup.htmlfunc ( *Conn) (, string) error { , := .openDB(, OPEN_READONLY|OPEN_URI)if != nil {return } , := .backupInit(.handle, , , "main")if != nil {return }defer .Close() _, = .Step(-1)return}// BackupInit initializes a backup operation to copy the content of one database into another.//// BackupInit opens the SQLite database file dstURI,// then initializes a backup that copies the contents of srcDB on the src connection// to the "main" database in dstURI.//// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupinitfunc ( *Conn) (, string) (*Backup, error) { , := .openDB(, OPEN_READWRITE|OPEN_CREATE|OPEN_URI)if != nil {returnnil, }return .backupInit(, "main", .handle, )}func ( *Conn) ( ptr_t, string, ptr_t, string) (*Backup, error) {defer .arena.Mark()() := .arena.String() := .arena.String() := if .handle == { = } := ptr_t(.wrp.Xsqlite3_backup_init(int32(), int32(),int32(), int32()))if == 0 {defer .closeDB() := res_t(.wrp.Xsqlite3_errcode(int32()))returnnil, .errorFor(, ) }return &Backup{c: ,otherc: ,handle: , }, nil}// Close finishes a backup operation.//// It is safe to close a nil, zero or closed Backup.//// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinishfunc ( *Backup) () error {if == nil || .handle == 0 {returnnil } := res_t(.c.wrp.Xsqlite3_backup_finish(int32(.handle))) .c.closeDB(.otherc) .handle = 0return .c.error()}// Step copies up to nPage pages between the source and destination databases.// If nPage is negative, all remaining source pages are copied.//// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupstepfunc ( *Backup) ( int) ( bool, error) { := res_t(.c.wrp.Xsqlite3_backup_step(int32(.handle), int32()))if == _DONE {returntrue, nil }returnfalse, .c.error()}// Remaining returns the number of pages still to be backed up// at the conclusion of the most recent [Backup.Step].//// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupremainingfunc ( *Backup) () int { := int32(.c.wrp.Xsqlite3_backup_remaining(int32(.handle)))returnint()}// PageCount returns the total number of pages in the source database// at the conclusion of the most recent [Backup.Step].//// https://sqlite.org/c3ref/backup_finish.html#sqlite3backuppagecountfunc ( *Backup) () int { := int32(.c.wrp.Xsqlite3_backup_pagecount(int32(.handle)))returnint()}
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.