// Package sqlite3 wraps the C SQLite API.
package sqlite3 import ( _ sqlite3_wasm ) type configKey struct{} // WithMaxMemory returns a derived context that configures // each SQLite connection not to use more than max amount of memory. func ( context.Context, int64) context.Context { if < 0 || > 65536*65536 { panic(errutil.OOMErr) } return context.WithValue(, configKey{}, /65536) } var _ sqlite3_wasm.Xenv = &env{} type env struct{ *sqlite3_wrap.Wrapper } func createWrapper( context.Context) (*sqlite3_wrap.Wrapper, error) { := &sqlite3_wrap.Memory{Max: 4096} // 256MB if bits.UintSize < 64 { .Max = 512 // 32MB } if , := .Value(configKey{}).(int64); { .Max = } .Grow(5, .Max) // 320KB := &env{&sqlite3_wrap.Wrapper{Memory: }} .Module = sqlite3_wasm.New() .X_initialize() return .Wrapper, nil } func ( *env) () sqlite3_wasm.Memory { return .Memory } // VFS functions. func ( *env) (, , int32) int32 { := .Bytes(ptr_t(), int64()) , := rand.Reader.Read() return int32() } func ( *env) (, int32) int32 { time.Sleep(time.Duration() * time.Microsecond) return _OK } func ( *env) (, int32) int32 { , := julianday.Date(time.Now()) := *86_400_000 + /1_000_000 .Write64(ptr_t(), uint64()) return int32(_OK) } func ( *env) ( int32) int32 { if vfs.Find(.ReadString(ptr_t(), _MAX_NAME)) != nil { return 1 } return 0 } //go:linkname vfsFullPathname github.com/ncruces/go-sqlite3/vfs.vfsFullPathname func vfsFullPathname( *sqlite3_wrap.Wrapper, , , , int32) int32 func ( *env) (, , , int32) int32 { return vfsFullPathname(.Wrapper, , , , ) } //go:linkname vfsDelete github.com/ncruces/go-sqlite3/vfs.vfsDelete func vfsDelete( *sqlite3_wrap.Wrapper, , , int32) int32 func ( *env) (, , int32) int32 { return vfsDelete(.Wrapper, , , ) } //go:linkname vfsAccess github.com/ncruces/go-sqlite3/vfs.vfsAccess func vfsAccess( *sqlite3_wrap.Wrapper, , , , int32) int32 func ( *env) (, , , int32) int32 { return vfsAccess(.Wrapper, , , , ) } //go:linkname vfsOpen github.com/ncruces/go-sqlite3/vfs.vfsOpen func vfsOpen( *sqlite3_wrap.Wrapper, , , , , , int32) int32 func ( *env) (, , , , , int32) int32 { return vfsOpen(.Wrapper, , , , , , ) } //go:linkname vfsClose github.com/ncruces/go-sqlite3/vfs.vfsClose func vfsClose( *sqlite3_wrap.Wrapper, int32) int32 func ( *env) ( int32) int32 { return vfsClose(.Wrapper, ) } //go:linkname vfsRead github.com/ncruces/go-sqlite3/vfs.vfsRead func vfsRead( *sqlite3_wrap.Wrapper, , , int32, int64) int32 func ( *env) (, , int32, int64) int32 { return vfsRead(.Wrapper, , , , ) } //go:linkname vfsWrite github.com/ncruces/go-sqlite3/vfs.vfsWrite func vfsWrite( *sqlite3_wrap.Wrapper, , , int32, int64) int32 func ( *env) (, , int32, int64) int32 { return vfsWrite(.Wrapper, , , , ) } //go:linkname vfsTruncate github.com/ncruces/go-sqlite3/vfs.vfsTruncate func vfsTruncate( *sqlite3_wrap.Wrapper, int32, int64) int32 func ( *env) ( int32, int64) int32 { return vfsTruncate(.Wrapper, , ) } //go:linkname vfsSync github.com/ncruces/go-sqlite3/vfs.vfsSync func vfsSync( *sqlite3_wrap.Wrapper, , int32) int32 func ( *env) (, int32) int32 { return vfsSync(.Wrapper, , ) } //go:linkname vfsFileSize github.com/ncruces/go-sqlite3/vfs.vfsFileSize func vfsFileSize( *sqlite3_wrap.Wrapper, , int32) int32 func ( *env) (, int32) int32 { return vfsFileSize(.Wrapper, , ) } //go:linkname vfsLock github.com/ncruces/go-sqlite3/vfs.vfsLock func vfsLock( *sqlite3_wrap.Wrapper, , int32) int32 func ( *env) ( int32, int32) int32 { return vfsLock(.Wrapper, , ) } //go:linkname vfsUnlock github.com/ncruces/go-sqlite3/vfs.vfsUnlock func vfsUnlock( *sqlite3_wrap.Wrapper, , int32) int32 func ( *env) (, int32) int32 { return vfsUnlock(.Wrapper, , ) } //go:linkname vfsCheckReservedLock github.com/ncruces/go-sqlite3/vfs.vfsCheckReservedLock func vfsCheckReservedLock( *sqlite3_wrap.Wrapper, , int32) int32 func ( *env) (, int32) int32 { return vfsCheckReservedLock(.Wrapper, , ) } //go:linkname vfsFileControl github.com/ncruces/go-sqlite3/vfs.vfsFileControl func vfsFileControl( *sqlite3_wrap.Wrapper, , , int32) int32 func ( *env) (, , int32) int32 { return vfsFileControl(.Wrapper, , , ) } //go:linkname vfsSectorSize github.com/ncruces/go-sqlite3/vfs.vfsSectorSize func vfsSectorSize( *sqlite3_wrap.Wrapper, int32) int32 func ( *env) ( int32) int32 { return vfsSectorSize(.Wrapper, ) } //go:linkname vfsDeviceCharacteristics github.com/ncruces/go-sqlite3/vfs.vfsDeviceCharacteristics func vfsDeviceCharacteristics( *sqlite3_wrap.Wrapper, int32) int32 func ( *env) ( int32) int32 { return vfsDeviceCharacteristics(.Wrapper, ) } //go:linkname vfsShmBarrier github.com/ncruces/go-sqlite3/vfs.vfsShmBarrier func vfsShmBarrier( *sqlite3_wrap.Wrapper, int32) func ( *env) ( int32) { vfsShmBarrier(.Wrapper, ) } //go:linkname vfsShmMap github.com/ncruces/go-sqlite3/vfs.vfsShmMap func vfsShmMap( *sqlite3_wrap.Wrapper, , , , , int32) int32 func ( *env) (, , , , int32) int32 { return vfsShmMap(.Wrapper, , , , , ) } //go:linkname vfsShmLock github.com/ncruces/go-sqlite3/vfs.vfsShmLock func vfsShmLock( *sqlite3_wrap.Wrapper, , , , int32) int32 func ( *env) (, , , int32) int32 { return vfsShmLock(.Wrapper, , , , ) } //go:linkname vfsShmUnmap github.com/ncruces/go-sqlite3/vfs.vfsShmUnmap func vfsShmUnmap( *sqlite3_wrap.Wrapper, , int32) int32 func ( *env) (, int32) int32 { return vfsShmUnmap(.Wrapper, , ) }