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

table.update(...) method #35

Closed
simonw opened this issue Jun 30, 2019 · 2 comments
Closed

table.update(...) method #35

simonw opened this issue Jun 30, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jun 30, 2019

Spun off from #23 - this method will allow a user to update a specific row.

Currently the only way to do that it is to call .upsert({full record}) with the primary key field matching an existing record - but this does not support partial updates.

db["events"].update(3, {"name": "Renamed"})

This method only works on an existing table, so there's no need for a pk="id" specifier - it can detect the primary key by looking at the table.

If the primary key is compound the first argument can be a tuple:

db["events_venues"].update((3, 2), {"custom_label": "Label"})

The method can be called without the second dictionary argument. Doing this selects the row specified by the primary key (throwing an error if it does not exist) and remembers it so that chained operations can be carried out - see proposal in #23 (comment)

@simonw simonw added the enhancement New feature or request label Jun 30, 2019
@simonw
Copy link
Owner Author

simonw commented Jul 14, 2019

The last touched primary key should go in last_pk.

The ``dogs.last_pk`` property will return the last inserted primary key value, if you specified one. This can be very useful when writing code that creates foreign keys or many-to-many relationships.

@simonw
Copy link
Owner Author

simonw commented Jul 14, 2019

Should this support both dictionaries AND keyword arguments?

db["events_venues"].update((3, 2), custom_label="Label")

Pros: this is quite nice to look at.
Cons: would have to continue supporting dictionaries as well, since otherwise you won't be able to update columns with names that are not valid Python identifiers. So now there are two ways.

I'm going to stick with dictionaries only for the moment.

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

1 participant