mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
db[table].create(..., transform=True) and create-table --transform
Closes #467
This commit is contained in:
parent
36ffcafb1a
commit
104f37fa4d
6 changed files with 189 additions and 11 deletions
|
|
@ -1453,9 +1453,24 @@ def create_database(path, enable_wal, init_spatialite, load_extension):
|
|||
is_flag=True,
|
||||
help="If table already exists, replace it",
|
||||
)
|
||||
@click.option(
|
||||
"--transform",
|
||||
is_flag=True,
|
||||
help="If table already exists, try to transform the schema",
|
||||
)
|
||||
@load_extension_option
|
||||
def create_table(
|
||||
path, table, columns, pk, not_null, default, fk, ignore, replace, load_extension
|
||||
path,
|
||||
table,
|
||||
columns,
|
||||
pk,
|
||||
not_null,
|
||||
default,
|
||||
fk,
|
||||
ignore,
|
||||
replace,
|
||||
transform,
|
||||
load_extension,
|
||||
):
|
||||
"""
|
||||
Add a table with the specified columns. Columns should be specified using
|
||||
|
|
@ -1490,6 +1505,8 @@ def create_table(
|
|||
return
|
||||
elif replace:
|
||||
db[table].drop()
|
||||
elif transform:
|
||||
pass
|
||||
else:
|
||||
raise click.ClickException(
|
||||
'Table "{}" already exists. Use --replace to delete and replace it.'.format(
|
||||
|
|
@ -1497,7 +1514,12 @@ def create_table(
|
|||
)
|
||||
)
|
||||
db[table].create(
|
||||
coltypes, pk=pk, not_null=not_null, defaults=dict(default), foreign_keys=fk
|
||||
coltypes,
|
||||
pk=pk,
|
||||
not_null=not_null,
|
||||
defaults=dict(default),
|
||||
foreign_keys=fk,
|
||||
transform=transform,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue