mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Also made it so .duplicate() raises new NoTable exception rather than raising an AssertionError if the source table does not exist.
This commit is contained in:
parent
da030d49fd
commit
c710ade644
7 changed files with 80 additions and 3 deletions
|
|
@ -5,7 +5,7 @@ from datetime import datetime
|
|||
import hashlib
|
||||
import pathlib
|
||||
import sqlite_utils
|
||||
from sqlite_utils.db import AlterError, BadMultiValues, DescIndex
|
||||
from sqlite_utils.db import AlterError, BadMultiValues, DescIndex, NoTable
|
||||
from sqlite_utils.utils import maximize_csv_field_size_limit
|
||||
from sqlite_utils import recipes
|
||||
import textwrap
|
||||
|
|
@ -1465,6 +1465,27 @@ def create_table(
|
|||
)
|
||||
|
||||
|
||||
@cli.command(name="duplicate")
|
||||
@click.argument(
|
||||
"path",
|
||||
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
@click.argument("table")
|
||||
@click.argument("new_table")
|
||||
@load_extension_option
|
||||
def create_table(path, table, new_table, load_extension):
|
||||
"""
|
||||
Create a duplicate of this table, copying across the schema and all row data.
|
||||
"""
|
||||
db = sqlite_utils.Database(path)
|
||||
_load_extensions(db, load_extension)
|
||||
try:
|
||||
db[table].duplicate(new_table)
|
||||
except NoTable:
|
||||
raise click.ClickException('Table "{}" does not exist'.format(table))
|
||||
|
||||
|
||||
@cli.command(name="drop-table")
|
||||
@click.argument(
|
||||
"path",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue