yhat / db.py

db.py is an easier way to interact with your databases
BSD 2-Clause "Simplified" License
1.22k stars 111 forks source link

Can db.py read a in-memory SQLite db? #62

Closed garaud closed 9 years ago

garaud commented 9 years ago

Hi,

Suppose, for demo or test purposes, I have a in-memory SQLite database such as:

Can I read it from db.DB? I test:

from db import DB
db = DB(filename="sqlite://", dbtype='sqlite')

without success. Is there a plan to support it?

Thanks ! Cheers, Damien G.

garaud commented 9 years ago

OK, sorry. When I read the python docs about the sqlite3 module, I can do:

db = DB(filename=":memory:", dbtype='sqlite')

without error. But I can't see the table that I previously created before calling db.py I don't know if the in-memory db is correctly loaded.

garaud commented 9 years ago

My bad (again) :

Every :memory: database is distinct from every other. So, opening two database connections each with the filename ":memory:" will create two independent in-memory databases.

from https://www.sqlite.org/inmemorydb.html I understand that each time I created a new connection with the ":memory:" parameter, with SQLAlchemy, db.py or sqlite3, this is a new in-memory database. I have not found a way to attach a connection to an existing in-memory DB (and it's surely safe).

I'll just create a temporary db filename and voilà.

Damien