simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.62k stars 109 forks source link

Document that running `db.transform()` tidies up the schema indentation #564

Closed simonw closed 1 year ago

simonw commented 1 year ago

... and it turns out running .transform() with no arguments still fixes the format of the schema!

>>> db["log"].add_column("foo", str)
<Table log (id, name2, age, weight, foo)>
>>> db["log"].add_column("bar", str)
<Table log (id, name2, age, weight, foo, bar)>
>>> db["log"].add_column("baz", str)
<Table log (id, name2, age, weight, foo, bar, baz)>
>>> print(db["log"].schema)
CREATE TABLE "log" (
   [id] INTEGER PRIMARY KEY,
   [name2] TEXT,
   [age] INTEGER,
   [weight] FLOAT
, [foo] TEXT, [bar] TEXT, [baz] TEXT)
>>> db["log"].transform()
<Table log (id, name2, age, weight, foo, bar, baz)>
>>> print(db["log"].schema)
CREATE TABLE "log" (
   [id] INTEGER PRIMARY KEY,
   [name2] TEXT,
   [age] INTEGER,
   [weight] FLOAT,
   [foo] TEXT,
   [bar] TEXT,
   [baz] TEXT
)

Originally posted by @simonw in https://github.com/simonw/llm/issues/65#issuecomment-1618347727