github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/api.go (about) 1 // Package vfs wraps the C SQLite VFS API. 2 package vfs 3 4 import ( 5 "context" 6 "io" 7 8 "github.com/tetratelabs/wazero/api" 9 ) 10 11 // A VFS defines the interface between the SQLite core and the underlying operating system. 12 // 13 // Use sqlite3.ErrorCode or sqlite3.ExtendedErrorCode to return specific error codes to SQLite. 14 // 15 // https://sqlite.org/c3ref/vfs.html 16 type VFS interface { 17 Open(name string, flags OpenFlag) (File, OpenFlag, error) 18 Delete(name string, syncDir bool) error 19 Access(name string, flags AccessFlag) (bool, error) 20 FullPathname(name string) (string, error) 21 } 22 23 // VFSFilename extends VFS with the ability to use Filename 24 // objects for opening files. 25 // 26 // https://sqlite.org/c3ref/filename.html 27 type VFSFilename interface { 28 VFS 29 OpenFilename(name *Filename, flags OpenFlag) (File, OpenFlag, error) 30 } 31 32 // A File represents an open file in the OS interface layer. 33 // 34 // Use sqlite3.ErrorCode or sqlite3.ExtendedErrorCode to return specific error codes to SQLite. 35 // In particular, sqlite3.BUSY is necessary to correctly implement lock methods. 36 // 37 // https://sqlite.org/c3ref/io_methods.html 38 type File interface { 39 Close() error 40 ReadAt(p []byte, off int64) (n int, err error) 41 WriteAt(p []byte, off int64) (n int, err error) 42 Truncate(size int64) error 43 Sync(flags SyncFlag) error 44 Size() (int64, error) 45 Lock(lock LockLevel) error 46 Unlock(lock LockLevel) error 47 CheckReservedLock() (bool, error) 48 SectorSize() int 49 DeviceCharacteristics() DeviceCharacteristic 50 } 51 52 // FileLockState extends File to implement the 53 // SQLITE_FCNTL_LOCKSTATE file control opcode. 54 // 55 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntllockstate 56 type FileLockState interface { 57 File 58 LockState() LockLevel 59 } 60 61 // FileChunkSize extends File to implement the 62 // SQLITE_FCNTL_CHUNK_SIZE file control opcode. 63 // 64 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlchunksize 65 type FileChunkSize interface { 66 File 67 ChunkSize(size int) 68 } 69 70 // FileSizeHint extends File to implement the 71 // SQLITE_FCNTL_SIZE_HINT file control opcode. 72 // 73 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlsizehint 74 type FileSizeHint interface { 75 File 76 SizeHint(size int64) error 77 } 78 79 // FileHasMoved extends File to implement the 80 // SQLITE_FCNTL_HAS_MOVED file control opcode. 81 // 82 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlhasmoved 83 type FileHasMoved interface { 84 File 85 HasMoved() (bool, error) 86 } 87 88 // FileOverwrite extends File to implement the 89 // SQLITE_FCNTL_OVERWRITE file control opcode. 90 // 91 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntloverwrite 92 type FileOverwrite interface { 93 File 94 Overwrite() error 95 } 96 97 // FilePersistentWAL extends File to implement the 98 // SQLITE_FCNTL_PERSIST_WAL file control opcode. 99 // 100 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlpersistwal 101 type FilePersistentWAL interface { 102 File 103 PersistentWAL() bool 104 SetPersistentWAL(bool) 105 } 106 107 // FilePowersafeOverwrite extends File to implement the 108 // SQLITE_FCNTL_POWERSAFE_OVERWRITE file control opcode. 109 // 110 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlpowersafeoverwrite 111 type FilePowersafeOverwrite interface { 112 File 113 PowersafeOverwrite() bool 114 SetPowersafeOverwrite(bool) 115 } 116 117 // FileCommitPhaseTwo extends File to implement the 118 // SQLITE_FCNTL_COMMIT_PHASETWO file control opcode. 119 // 120 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlcommitphasetwo 121 type FileCommitPhaseTwo interface { 122 File 123 CommitPhaseTwo() error 124 } 125 126 // FileBatchAtomicWrite extends File to implement the 127 // SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 128 // and SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE file control opcodes. 129 // 130 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlbeginatomicwrite 131 type FileBatchAtomicWrite interface { 132 File 133 BeginAtomicWrite() error 134 CommitAtomicWrite() error 135 RollbackAtomicWrite() error 136 } 137 138 // FilePragma extends File to implement the 139 // SQLITE_FCNTL_PRAGMA file control opcode. 140 // 141 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlpragma 142 type FilePragma interface { 143 File 144 Pragma(name, value string) (string, error) 145 } 146 147 // FileCheckpoint extends File to implement the 148 // SQLITE_FCNTL_CKPT_START and SQLITE_FCNTL_CKPT_DONE 149 // file control opcodes. 150 // 151 // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlckptstart 152 type FileCheckpoint interface { 153 File 154 CheckpointDone() error 155 CheckpointStart() error 156 } 157 158 // FileSharedMemory extends File to possibly implement 159 // shared-memory for the WAL-index. 160 // The same shared-memory instance must be returned 161 // for the entire life of the file. 162 // It's OK for SharedMemory to return nil. 163 type FileSharedMemory interface { 164 File 165 SharedMemory() SharedMemory 166 } 167 168 // SharedMemory is a shared-memory WAL-index implementation. 169 // Use [NewSharedMemory] to create a shared-memory. 170 type SharedMemory interface { 171 shmMap(context.Context, api.Module, int32, int32, bool) (uint32, error) 172 shmLock(int32, int32, _ShmFlag) error 173 shmUnmap(bool) 174 io.Closer 175 }