Use :prefix to query attached databases#175
Use :prefix to query attached databases#175sbaildon wants to merge 5 commits intoelixir-sqlite:mainfrom
Conversation
|
I think prefix was for EDIT: |
https://www.sqlite.org/lang_attach.html the prefixed table name is intentionally not quoted because statements expect a bare qualifier without quotes like `INSERT INTO schema-name.table-name`
|
Can you do me a favor as well and remove this and let the integration tests run. |
|
We'll need to fix the assertions encountered with |
|
I need to understand why the attached database seemingly doesn't exist when running the ecto library tests, but I think we're close. |
| reference_name(ref, table, name), | ||
| " REFERENCES ", | ||
| quote_table(ref.prefix || table.prefix, ref.table), | ||
| quote_table(nil, ref.table), |
There was a problem hiding this comment.
Is this right? If someone has a prefix specified on the schema or relationship it should be put here.
There was a problem hiding this comment.
Ah yes I think that's right
I tried this and got an error:
sqlite> attach ":memory:" as attached_db
sqlite> create table attached_db.things (thing string not null);
sqlite> create table attached_db.refs (thing_id bigint not null references attached_db.things(id));
Parse error: near ".": syntax error
s (thing_id bigint not null references attached_db.things(id));
error here ---^
but quoting the entire reference works:
sqlite> attach ":memory:" as attached_db
sqlite> create table attached_db.things (thing string not null);
sqlite> create table attached_db.refs (thing_id bigint not null references 'attached_db.things(id)');
There was a problem hiding this comment.
Take a look at how the posgres and mysql adapters do this. I want to try and stay as close to what they do. I haven't looked at it in a long time (like 2 years) and we probably need to make adjustments.
SQLite allows attached databases, and their tables can be referenced by prefixing the schema name
I think it makes sense to use ecto's
:prefixoption to query these schemas.I'm currently using this patch like...
Where I'm wrapping a transaction with ATTACH/DETACH to insert rows with transactional guarantees across both databases