-
Hello, I am new to tinydb, but is it possible to rename existing field with losing all the data is assigned to it, and also is any easy way to delete a field with all its data like in mysql (ALTER TABLE table_name DROP COLUMN column_name;) Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Ok, how to delete i found :) table.update(delete('name')) But how to rename key i have no idea. |
Beta Was this translation helpful? Give feedback.
-
I think you should be able to define a custom operation like this: def rename(from, to):
def transform(doc):
doc[to] = doc.pop(from, None)
return transform and use it just like table.update(rename('old_name', 'new_name')) Does this work for you? |
Beta Was this translation helpful? Give feedback.
-
Thanks, it works, except i had to rename "from" to something, as it is not allowed as variable:) But it works great. |
Beta Was this translation helpful? Give feedback.
I think you should be able to define a custom operation like this:
and use it just like
delete('name')
:Does this work for you?