mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 14:09:13 +00:00
Docs.
This commit is contained in:
10
vfs/api.go
10
vfs/api.go
@@ -15,7 +15,7 @@ type VFS interface {
|
||||
FullPathname(name string) (string, error)
|
||||
}
|
||||
|
||||
// VFSParams extends [VFS] to with the ability to handle URI parameters
|
||||
// VFSParams extends VFS to with the ability to handle URI parameters
|
||||
// through the OpenParams method.
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/uri_boolean.html
|
||||
@@ -44,7 +44,7 @@ type File interface {
|
||||
DeviceCharacteristics() DeviceCharacteristic
|
||||
}
|
||||
|
||||
// FileLockState extends [File] to implement the
|
||||
// FileLockState extends File to implement the
|
||||
// SQLITE_FCNTL_LOCKSTATE file control opcode.
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
|
||||
@@ -53,7 +53,7 @@ type FileLockState interface {
|
||||
LockState() LockLevel
|
||||
}
|
||||
|
||||
// FileSizeHint extends [File] to implement the
|
||||
// FileSizeHint extends File to implement the
|
||||
// SQLITE_FCNTL_SIZE_HINT file control opcode.
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
|
||||
@@ -62,7 +62,7 @@ type FileSizeHint interface {
|
||||
SizeHint(size int64) error
|
||||
}
|
||||
|
||||
// FileHasMoved extends [File] to implement the
|
||||
// FileHasMoved extends File to implement the
|
||||
// SQLITE_FCNTL_HAS_MOVED file control opcode.
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
|
||||
@@ -71,7 +71,7 @@ type FileHasMoved interface {
|
||||
HasMoved() (bool, error)
|
||||
}
|
||||
|
||||
// FilePowersafeOverwrite extends [File] to implement the
|
||||
// FilePowersafeOverwrite extends File to implement the
|
||||
// SQLITE_FCNTL_POWERSAFE_OVERWRITE file control opcode.
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
|
||||
|
||||
@@ -21,6 +21,7 @@ func init() {
|
||||
|
||||
var (
|
||||
memoryMtx sync.Mutex
|
||||
// +checklocks:memoryMtx
|
||||
memoryDBs = map[string]*memDB{}
|
||||
)
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func (memVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, err
|
||||
db = new(memDB)
|
||||
}
|
||||
if shared {
|
||||
memoryDBs[name[1:]] = db
|
||||
memoryDBs[name[1:]] = db // +checklocksignore: lock is held
|
||||
}
|
||||
|
||||
return &memFile{
|
||||
|
||||
@@ -23,6 +23,7 @@ func init() {
|
||||
|
||||
var (
|
||||
readerMtx sync.RWMutex
|
||||
// +checklocks:readerMtx
|
||||
readerDBs = map[string]SizeReaderAt{}
|
||||
)
|
||||
|
||||
|
||||
@@ -5,16 +5,20 @@ import "sync"
|
||||
var (
|
||||
// +checklocks:vfsRegistryMtx
|
||||
vfsRegistry map[string]VFS
|
||||
vfsRegistryMtx sync.Mutex
|
||||
vfsRegistryMtx sync.RWMutex
|
||||
)
|
||||
|
||||
// Find returns a VFS given its name.
|
||||
// If there is no match, nil is returned.
|
||||
// If name is empty, the default VFS is returned.
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/vfs_find.html
|
||||
func Find(name string) VFS {
|
||||
vfsRegistryMtx.Lock()
|
||||
defer vfsRegistryMtx.Unlock()
|
||||
if name == "" || name == "os" {
|
||||
return vfsOS{}
|
||||
}
|
||||
vfsRegistryMtx.RLock()
|
||||
defer vfsRegistryMtx.RUnlock()
|
||||
return vfsRegistry[name]
|
||||
}
|
||||
|
||||
@@ -22,6 +26,9 @@ func Find(name string) VFS {
|
||||
//
|
||||
// https://www.sqlite.org/c3ref/vfs_find.html
|
||||
func Register(name string, vfs VFS) {
|
||||
if name == "" || name == "os" {
|
||||
return
|
||||
}
|
||||
vfsRegistryMtx.Lock()
|
||||
defer vfsRegistryMtx.Unlock()
|
||||
if vfsRegistry == nil {
|
||||
|
||||
25
vfs/vfs.go
25
vfs/vfs.go
@@ -14,10 +14,10 @@ import (
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
)
|
||||
|
||||
// ExportHostFunctions is an internal API users need not call directly.
|
||||
//
|
||||
// ExportHostFunctions registers the required VFS host functions
|
||||
// with the provided env module.
|
||||
//
|
||||
// Users of the [github.com/ncruces/go-sqlite3] package need not call this directly.
|
||||
func ExportHostFunctions(env wazero.HostModuleBuilder) wazero.HostModuleBuilder {
|
||||
util.ExportFuncII(env, "go_vfs_find", vfsFind)
|
||||
util.ExportFuncIIJ(env, "go_localtime", vfsLocaltime)
|
||||
@@ -49,15 +49,13 @@ type vfsState struct {
|
||||
files []File
|
||||
}
|
||||
|
||||
// NewContext is an internal API users need not call directly.
|
||||
//
|
||||
// NewContext creates a new context to hold [api.Module] specific VFS data.
|
||||
//
|
||||
// This context should be passed to any [api.Function] calls that might
|
||||
// The context should be passed to any [api.Function] calls that might
|
||||
// generate VFS host callbacks.
|
||||
//
|
||||
// The returned [io.Closer] should be closed after the [api.Module] is closed,
|
||||
// to release any associated resources.
|
||||
//
|
||||
// Users of the [github.com/ncruces/go-sqlite3] package need not call this directly.
|
||||
func NewContext(ctx context.Context) (context.Context, io.Closer) {
|
||||
vfs := new(vfsState)
|
||||
return context.WithValue(ctx, vfsKey{}, vfs), vfs
|
||||
@@ -75,7 +73,7 @@ func (vfs *vfsState) Close() error {
|
||||
|
||||
func vfsFind(ctx context.Context, mod api.Module, zVfsName uint32) uint32 {
|
||||
name := util.ReadString(mod, zVfsName, _MAX_STRING)
|
||||
if Find(name) != nil {
|
||||
if vfs := Find(name); vfs != nil && vfs != (vfsOS{}) {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
@@ -399,13 +397,10 @@ func vfsURIParameters(ctx context.Context, mod api.Module, zPath uint32, flags O
|
||||
}
|
||||
|
||||
func vfsGet(mod api.Module, pVfs uint32) VFS {
|
||||
if pVfs == 0 {
|
||||
return vfsOS{}
|
||||
}
|
||||
const zNameOffset = 16
|
||||
name := util.ReadString(mod, util.ReadUint32(mod, pVfs+zNameOffset), _MAX_STRING)
|
||||
if name == "os" {
|
||||
return vfsOS{}
|
||||
var name string
|
||||
if pVfs != 0 {
|
||||
const zNameOffset = 16
|
||||
name = util.ReadString(mod, util.ReadUint32(mod, pVfs+zNameOffset), _MAX_STRING)
|
||||
}
|
||||
if vfs := Find(name); vfs != nil {
|
||||
return vfs
|
||||
|
||||
Reference in New Issue
Block a user