github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/readervfs/api.go (about) 1 // Package readervfs implements an SQLite VFS for immutable databases. 2 // 3 // The "reader" [vfs.VFS] permits accessing any [io.ReaderAt] 4 // as an immutable SQLite database. 5 // 6 // Importing package readervfs registers the VFS: 7 // 8 // import _ "github.com/ncruces/go-sqlite3/vfs/readervfs" 9 package readervfs 10 11 import ( 12 "sync" 13 14 "github.com/ncruces/go-sqlite3/util/ioutil" 15 "github.com/ncruces/go-sqlite3/vfs" 16 ) 17 18 func init() { 19 vfs.Register("reader", readerVFS{}) 20 } 21 22 var ( 23 readerMtx sync.RWMutex 24 // +checklocks:readerMtx 25 readerDBs = map[string]ioutil.SizeReaderAt{} 26 ) 27 28 // Create creates an immutable database from reader. 29 // The caller should ensure that data from reader does not mutate, 30 // otherwise SQLite might return incorrect query results and/or [sqlite3.CORRUPT] errors. 31 func Create(name string, reader ioutil.SizeReaderAt) { 32 readerMtx.Lock() 33 defer readerMtx.Unlock() 34 readerDBs[name] = reader 35 } 36 37 // Delete deletes a shared memory database. 38 func Delete(name string) { 39 readerMtx.Lock() 40 defer readerMtx.Unlock() 41 delete(readerDBs, name) 42 }