Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extracts= option for insert/update/etc #46

Closed
simonw opened this issue Jul 23, 2019 · 3 comments
Closed

extracts= option for insert/update/etc #46

simonw opened this issue Jul 23, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jul 23, 2019

Relates to #42 and #44. I want the ability to extract values out into lookup tables during bulk insert/upsert operations.

db.insert_all(rows, extracts=["species"])

  • creates species table for values in the species column

db.insert_all(rows, extracts={"species": "Species"})

  • as above but the new table is called Species.
@simonw simonw added the enhancement New feature or request label Jul 23, 2019
@simonw
Copy link
Owner Author

simonw commented Jul 23, 2019

This will play very well with the new ability to specify these arguments in the class constructor, like so:

    table = db.table("trees", extracts={"species_id": "Species"})
    table.insert_all([{
        "id": 1,
        "species_id": "Oak",
    }, {
        "id": 2,
        "species_id": "Oak",
    }, {
        "id": 3,
        "species_id": "Palm",
    }])

simonw added a commit that referenced this issue Jul 23, 2019
@simonw simonw closed this as completed in 941d281 Jul 23, 2019
simonw added a commit that referenced this issue Jul 24, 2019
@chrishas35
Copy link

@simonw any thoughts on allow extracts to specify the lookup column name? If I'm understanding the documentation right, .lookup() allows you to define the "value" column (the documentation uses name), but when you use extracts keyword as part of .insert(), .upsert() etc. the lookup must be done against a column named "value". I have an existing lookup table that I've populated with columns "id" and "name" as opposed to "id" and "value", and seems I can't use extracts=, unless I'm missing something...

Initial thought on how to do this would be to allow the dictionary value to be a tuple of table name column pair... so:

table = db.table("trees", extracts={"species_id": ("Species", "name"})

I haven't dug too much into the existing code yet, but does this make sense? Worth doing?

@simonw
Copy link
Owner Author

simonw commented Mar 1, 2020

That seems sensible to me. Opening a ticket for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants