racket / db

Other
20 stars 17 forks source link

shared in-memory SQLite #29

Open Rscho314 opened 2 years ago

Rscho314 commented 2 years ago

Hi Ryan,

version 3.37, SQLite allows multiple connections to a shared in-memory database.

I'd like to implement that. currently,

(sqlite3-connect #:database "file::memory:?cache=shared")

fails with:

file-or-directory-permissions: access failed
path: /home/raoul/Desktop/sqldf/file::memory:?cache=shared
system error: Aucun fichier ou dossier de ce type; errno=2
Context (plain; to see better errortrace context, re-run with C-u prefix):
/usr/share/racket/collects/db/private/sqlite3/connection.rkt:515:0 handle-status*
/usr/share/racket/collects/db/private/sqlite3/main.rkt:10:0 sqlite3-connect

However, I am confused about how to fix that. Indeed, I am unable to find the file /usr/share/racket/collects/db/private/sqlite3/connection.rkt. Is the file generated somehow?

Also, how should I install the package for testing? Doing raco pkg install in the root dir yields:

standard-module-name-resolver: collection not found for module path: db/private/pre collection: "db/private" in collection directories: /home/raoul/.racket/8.5/collects /home/raoul/Desktop/miniracket/racket/collects/ /home/raoul/Desktop/miniracket/racket/share/pkgs/racket-lib /home/raoul/Desktop/miniracket/racket/share/pkgs/base context...: /home/raoul/Desktop/miniracket/racket/collects/raco/raco.rkt:41:0 body of "/home/raoul/Desktop/miniracket/racket/collects/raco/raco.rkt" body of "/home/raoul/Desktop/miniracket/racket/collects/raco/main.rkt"

rmculpepper commented 2 years ago

Parts of the db collection are in the main repository, because (IIRC) raco setup uses SQLite databases to store metadata. The call to sqlite3_open_v2, for example, is here: https://github.com/racket/racket/blob/master/racket/collects/db/private/sqlite3/main.rkt.

The database argument should not be a string, which are always interpreted as paths by the Racket library. You should use a different kind of value, like (list 'memory #:shared #:name memdb1), and convert that to a string in sqlite3-connect. That function is written in an old style, by the way, and it should probably be updated to use match and definitions.