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

.transform(keep_table=...) option #571

Closed
simonw opened this issue Jul 22, 2023 · 1 comment
Closed

.transform(keep_table=...) option #571

simonw opened this issue Jul 22, 2023 · 1 comment
Labels
enhancement New feature or request python-library

Comments

@simonw
Copy link
Owner

simonw commented Jul 22, 2023

Also need a design for an option for the .transform() method to indicate that the new table should be created with a new name without dropping the old one.

I think keep_table="name_of_table" is good for this.

Originally posted by @simonw in #565 (comment)

@simonw simonw added enhancement New feature or request python-library labels Jul 22, 2023
@simonw
Copy link
Owner Author

simonw commented Jul 22, 2023

Demo:

>>> from sqlite_utils import Database
>>> db = Database(memory=True)
>>> db["foo"].insert({"name": "Cleo"})
<Table foo (name)>
>>> print(db["foo"].schema)
CREATE TABLE [foo] (
   [name] TEXT
)
>>> db["foo"].transform(not_null={"name"})
<Table foo (name)>
>>> print(db["foo"].schema)
CREATE TABLE "foo" (
   [name] TEXT NOT NULL
)
>>> db["foo"].transform(types={"name": int}, keep_table="kept")
<Table foo (name)>
>>> print(db.schema)
CREATE TABLE "kept" (
   [name] TEXT NOT NULL
);
CREATE TABLE "foo" (
   [name] INTEGER NOT NULL
);

@simonw simonw closed this as completed in 61aaa69 Jul 22, 2023
simonw added a commit that referenced this issue Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python-library
Projects
None yet
Development

No branches or pull requests

1 participant