Comments (4)
Maybe foreign_keys
could even optionally just be a list of columns - it could then attempt to detect the related tables based on some rules-of-thumb and raise an error if there's no obvious candidate.
Rules:
- If the column name ends in
_id
, remove that suffix and look for a matching table. - Try for a table which is the column name without the
_id
suffix with ans
appended to it - Try for a table that's the exact match for the column name
If none of these rules match, raise an error.
So the above example could be further simplified to:
db["usages"].insert_all(
usages_to_insert,
foreign_keys=["line_id", "definition_id"]
)
from sqlite-utils.
If I'm going to do this then I should make the other_table
and other_column
arguments optional here too:
sqlite-utils/sqlite_utils/cli.py
Lines 201 to 215 in 2fed87d
from sqlite-utils.
Still need to add this mechanism to .create_table()
- this code here is all that needs to be modified - it needs to learn to deal with the alternative syntax for foreign keys and guess the missing data if necessary:
sqlite-utils/sqlite_utils/db.py
Lines 115 to 119 in d645032
from sqlite-utils.
I'm going to reuse the ForeignKey
named tuple here:
sqlite-utils/sqlite_utils/db.py
Lines 17 to 19 in d645032
from sqlite-utils.
Related Issues (20)
- Get rid of test.utils.collapse_whitespace HOT 1
- CLI equivalents to `transform(add_foreign_keys=)` HOT 7
- .transform() fails to drop column if table is part of a view HOT 3
- New .add_foreign_key() can break if PRAGMA legacy_alter_table=ON and there's an invalid foreign key reference HOT 3
- `table.get(column=value)` option for retrieving things not by their primary key HOT 2
- Mechanism for de-registering registered SQL functions HOT 3
- Ability to tell if a Database is an in-memory one HOT 1
- `table.transform()` should preserve `rowid` values HOT 6
- Represent compound foreign keys in table.foreign_keys output HOT 2
- Cascading DELETE not working with Table.delete(pk) HOT 1
- Feature request: sqlite-utils insert-files should be able to convert fields
- Cannot find spatialite on arm64 linux HOT 1
- Move plugin directory into documentation
- `sqlite-utils transform` removes the `AUTOINCREMENT` keyword
- Pyhton 3.12 Bug report HOT 2
- Insert fails with `Error: Python int too large to convert to SQLite INTEGER`; can we use `NUMERIC` here? HOT 1
- str and int as aliases for text and integer HOT 2
- pyright and mypy showing access error messages for basic sqlite-utils usage
- Attached database tables representable by `Table`
- `table.upsert/upsert_all` fails to write row when `not_null` is absent and the schema definition includes `not_null` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlite-utils.