mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Better __repr__ for tables
This commit is contained in:
parent
127a836054
commit
58db40d67c
3 changed files with 9 additions and 4 deletions
|
|
@ -571,7 +571,7 @@ Introspection
|
|||
If you have loaded an existing table, you can use introspection to find out more about it::
|
||||
|
||||
>>> db["PlantType"]
|
||||
<sqlite_utils.db.Table at 0x10f5960b8>
|
||||
<Table PlantType (id, value)>
|
||||
|
||||
The ``.count`` property shows the current number of rows (``select count(*) from table``)::
|
||||
|
||||
|
|
|
|||
|
|
@ -380,7 +380,10 @@ class Table:
|
|||
|
||||
def __repr__(self):
|
||||
return "<Table {}{}>".format(
|
||||
self.name, " (does not exist yet)" if not self.exists else ""
|
||||
self.name,
|
||||
" (does not exist yet)"
|
||||
if not self.exists
|
||||
else " ({})".format(", ".join(c.name for c in self.columns)),
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -57,8 +57,10 @@ def test_schema(existing_db):
|
|||
assert "CREATE TABLE foo (text TEXT)" == existing_db["foo"].schema
|
||||
|
||||
|
||||
def test_table_repr(existing_db):
|
||||
assert "<Table foo>" == repr(existing_db["foo"])
|
||||
def test_table_repr(fresh_db):
|
||||
table = fresh_db["dogs"].insert({"name": "Cleo", "age": 4})
|
||||
assert "<Table dogs (name, age)>" == repr(table)
|
||||
assert "<Table cats (does not exist yet)>" == repr(fresh_db["cats"])
|
||||
|
||||
|
||||
def test_indexes(fresh_db):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue