2023-06-01 18:11:37 +01:00
|
|
|
// Package vfs wraps the C SQLite VFS API.
|
|
|
|
|
package vfs
|
2023-05-17 14:04:00 +01:00
|
|
|
|
2023-05-25 15:46:15 +01:00
|
|
|
import "net/url"
|
|
|
|
|
|
2023-05-19 13:47:12 +01:00
|
|
|
// A VFS defines the interface between the SQLite core and the underlying operating system.
|
|
|
|
|
//
|
2023-05-19 19:47:43 +01:00
|
|
|
// Use sqlite3.ErrorCode or sqlite3.ExtendedErrorCode to return specific error codes to SQLite.
|
2023-05-19 14:45:40 +01:00
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/vfs.html
|
2023-05-17 14:04:00 +01:00
|
|
|
type VFS interface {
|
|
|
|
|
Open(name string, flags OpenFlag) (File, OpenFlag, error)
|
2023-05-18 01:34:54 +01:00
|
|
|
Delete(name string, syncDir bool) error
|
2023-05-17 14:04:00 +01:00
|
|
|
Access(name string, flags AccessFlag) (bool, error)
|
|
|
|
|
FullPathname(name string) (string, error)
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 17:08:16 +01:00
|
|
|
// VFSParams extends VFS with the ability to handle URI parameters
|
2023-05-25 15:46:15 +01:00
|
|
|
// through the OpenParams method.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/uri_boolean.html
|
2023-05-25 15:46:15 +01:00
|
|
|
type VFSParams interface {
|
|
|
|
|
VFS
|
|
|
|
|
OpenParams(name string, flags OpenFlag, params url.Values) (File, OpenFlag, error)
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 01:56:38 +01:00
|
|
|
// VFSJournal extends VFS with the ability to open journals
|
|
|
|
|
// that need a reference to their corresponding database files.
|
|
|
|
|
//
|
|
|
|
|
// https://sqlite.org/c3ref/database_file_object.html
|
|
|
|
|
type VFSJournal interface {
|
|
|
|
|
VFS
|
|
|
|
|
OpenJournal(name string, flags OpenFlag, db File) (File, OpenFlag, error)
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 13:47:12 +01:00
|
|
|
// A File represents an open file in the OS interface layer.
|
|
|
|
|
//
|
2023-05-19 19:47:43 +01:00
|
|
|
// Use sqlite3.ErrorCode or sqlite3.ExtendedErrorCode to return specific error codes to SQLite.
|
2023-05-19 14:45:40 +01:00
|
|
|
// In particular, sqlite3.BUSY is necessary to correctly implement lock methods.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/io_methods.html
|
2023-05-17 14:04:00 +01:00
|
|
|
type File interface {
|
|
|
|
|
Close() error
|
|
|
|
|
ReadAt(p []byte, off int64) (n int, err error)
|
|
|
|
|
WriteAt(p []byte, off int64) (n int, err error)
|
|
|
|
|
Truncate(size int64) error
|
2023-05-18 01:34:54 +01:00
|
|
|
Sync(flags SyncFlag) error
|
2023-05-23 16:34:09 +01:00
|
|
|
Size() (int64, error)
|
2023-05-18 01:34:54 +01:00
|
|
|
Lock(lock LockLevel) error
|
|
|
|
|
Unlock(lock LockLevel) error
|
2023-05-17 14:04:00 +01:00
|
|
|
CheckReservedLock() (bool, error)
|
2023-05-18 16:00:34 +01:00
|
|
|
SectorSize() int
|
2023-05-19 02:00:16 +01:00
|
|
|
DeviceCharacteristics() DeviceCharacteristic
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 03:32:13 +01:00
|
|
|
// FileLockState extends File to implement the
|
2023-05-19 13:47:12 +01:00
|
|
|
// SQLITE_FCNTL_LOCKSTATE file control opcode.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntllockstate
|
2023-05-19 02:00:16 +01:00
|
|
|
type FileLockState interface {
|
|
|
|
|
File
|
|
|
|
|
LockState() LockLevel
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 03:32:13 +01:00
|
|
|
// FileSizeHint extends File to implement the
|
2023-05-19 13:47:12 +01:00
|
|
|
// SQLITE_FCNTL_SIZE_HINT file control opcode.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlsizehint
|
2023-05-19 02:00:16 +01:00
|
|
|
type FileSizeHint interface {
|
|
|
|
|
File
|
|
|
|
|
SizeHint(size int64) error
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 03:32:13 +01:00
|
|
|
// FileHasMoved extends File to implement the
|
2023-05-19 13:47:12 +01:00
|
|
|
// SQLITE_FCNTL_HAS_MOVED file control opcode.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlhasmoved
|
2023-05-19 02:00:16 +01:00
|
|
|
type FileHasMoved interface {
|
|
|
|
|
File
|
|
|
|
|
HasMoved() (bool, error)
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 02:43:45 +01:00
|
|
|
// FileOverwrite extends File to implement the
|
|
|
|
|
// SQLITE_FCNTL_OVERWRITE file control opcode.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntloverwrite
|
2023-09-21 02:43:45 +01:00
|
|
|
type FileOverwrite interface {
|
|
|
|
|
File
|
|
|
|
|
Overwrite() error
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 14:18:37 +00:00
|
|
|
// FilePersistentWAL extends File to implement the
|
|
|
|
|
// SQLITE_FCNTL_PERSIST_WAL file control opcode.
|
|
|
|
|
//
|
|
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlpersistwal
|
|
|
|
|
type FilePersistentWAL interface {
|
|
|
|
|
File
|
|
|
|
|
PersistentWAL() bool
|
|
|
|
|
SetPersistentWAL(bool)
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 03:32:13 +01:00
|
|
|
// FilePowersafeOverwrite extends File to implement the
|
2023-05-19 13:47:12 +01:00
|
|
|
// SQLITE_FCNTL_POWERSAFE_OVERWRITE file control opcode.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlpowersafeoverwrite
|
2023-05-19 02:00:16 +01:00
|
|
|
type FilePowersafeOverwrite interface {
|
|
|
|
|
File
|
|
|
|
|
PowersafeOverwrite() bool
|
|
|
|
|
SetPowersafeOverwrite(bool)
|
2023-05-17 14:04:00 +01:00
|
|
|
}
|
2023-06-02 11:13:42 +01:00
|
|
|
|
2024-03-14 14:18:37 +00:00
|
|
|
// FileCommitPhaseTwo extends File to implement the
|
2023-06-02 13:40:08 +01:00
|
|
|
// SQLITE_FCNTL_COMMIT_PHASETWO file control opcode.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlcommitphasetwo
|
2023-06-02 13:40:08 +01:00
|
|
|
type FileCommitPhaseTwo interface {
|
|
|
|
|
File
|
|
|
|
|
CommitPhaseTwo() error
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 11:13:42 +01:00
|
|
|
// FileBatchAtomicWrite extends File to implement the
|
|
|
|
|
// SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE
|
|
|
|
|
// and SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE file control opcodes.
|
|
|
|
|
//
|
2023-11-09 16:35:45 +00:00
|
|
|
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlbeginatomicwrite
|
2023-06-02 11:13:42 +01:00
|
|
|
type FileBatchAtomicWrite interface {
|
|
|
|
|
File
|
|
|
|
|
BeginAtomicWrite() error
|
|
|
|
|
CommitAtomicWrite() error
|
|
|
|
|
RollbackAtomicWrite() error
|
|
|
|
|
}
|