from Hacker News

Show HN: sqlite-memory-vfs - Open a SQLite db in Python without hitting disk

by michalc on 12/27/23, 8:05 PM with 14 comments

  • by ncruces on 12/28/23, 9:21 AM

    Recent SQLite builds include the memdb [1] VFS (and the associated sqlite3_serialize and sqlite3_deserialize APIs) by default. How does this compare?

    I'm also curious what use cases you had in mind. My SQLite wrapper reimplements the memdb [2] VFS mostly as an exercise of the VFS API, but it provides a few additional niceties. The backing memory doesn't need to be contiguous, nor is it copied when the DB grows/shrinks. This makes it possible to have significantly larger in memory DBs. I also make it easy to bootstrap the database from (e.g.) a file on disk, or data embed in the binary. It's not as easy, however, to access the DB bytes after the DB goes “live.”

    [1] https://www3.sqlite.org/src/file?name=src/memdb.c

    [2] https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs/memdb#s...

  • by gxt on 12/28/23, 2:50 AM

    Do you have benchmarks and how does this differ from pointing SQLite to /dev/shm ?
  • by up2isomorphism on 12/28/23, 6:33 AM

    It is funny people are doing SQL everything after the NoSQL hype. But why?
  • by throwaway81523 on 12/28/23, 5:08 AM

    import sqlite3

    conn = sqlite3.connect('%MEMORY%')

    Is there more to it than that?