Files
sqlite3/vfs/api.go

104 lines
3.0 KiB
Go
Raw Normal View History

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-05-19 13:47:12 +01:00
// https://www.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-06-02 03:32:13 +01:00
// VFSParams extends VFS to with the ability to handle URI parameters
2023-05-25 15:46:15 +01:00
// through the OpenParams method.
//
// https://www.sqlite.org/c3ref/uri_boolean.html
type VFSParams interface {
VFS
OpenParams(name string, flags OpenFlag, params url.Values) (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-05-19 13:47:12 +01:00
// https://www.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.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
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.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
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.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
2023-05-19 02:00:16 +01:00
type FileHasMoved interface {
File
HasMoved() (bool, error)
}
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.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
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
2023-06-02 13:40:08 +01:00
// FilePowersafeOverwrite extends File to implement the
// SQLITE_FCNTL_COMMIT_PHASETWO file control opcode.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
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.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
type FileBatchAtomicWrite interface {
File
BeginAtomicWrite() error
CommitAtomicWrite() error
RollbackAtomicWrite() error
}