Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Databases we support:
- DuckDB >=0.6
- SQLite (coming soon)


### Documentation

[Read the docs!](https://sqeleton.readthedocs.io)

### Basic usage

```python
Expand Down
68 changes: 67 additions & 1 deletion docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,72 @@ ddb: AbstractDatabase[NewAbstractDialect] = connect("duckdb://:memory:")
# ddb.dialect is now known to implement NewAbstractDialect.
```

### Query interpreter

In addition to query expressions, `Database.query()` can accept a generator, which will behave as an "interpreter".

The generator executes queries by yielding them.

Using a query interpreter also guarantees that subsequent calls to `.query()` will run in the same session. That can be useful for using temporary tables, or session variables.

Example:

```python
def sample_using_temp_table(db: Database, source_table: ITable, sample_size: int):
"This function creates a temporary table from a query and then samples rows from it"

results = []

def _sample_using_temp_table():
nonlocal results

yield code("CREATE TEMPORARY TABLE tmp1 AS {source_table}", source_table=source_table)

tbl = table('tmp1')
try:
results += yield sample(tbl, sample_size)
finally:
yield tbl.drop()

db.query(_sample_using_temp_table())
return results
```

### Query params

### Query interpreter
TODO

## Other features

### SQL client

Sqeleton comes with a simple built-in SQL client, in the form of a REPL, which accepts SQL commands, and a few special commands.

It accepts any database URL that is supported by Sqeleton. That can be useful for querying databases that don't have established clients.

You can call it using `sqeleton repl <url>`.

Example:

```bash
# Start a REPL session
$ sqeleton repl duckdb:///pii_test.ddb

# Run SQL
DuckDB> select (22::float / 7) as almost_pi
┏━━━━━━━━━━━━━━━━━━━┓
┃ almost_pi ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ 3.142857074737549 │
└───────────────────┘
1 rows

# Display help
DuckDB> ?

Commands:
?mytable - shows schema of table 'mytable'
* - shows list of all tables
*pattern - shows list of all tables with name like pattern
Otherwise, runs regular SQL query
```
196 changes: 123 additions & 73 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ trino = {version="^0.314.0", optional=true}
presto-python-client = {version="*", optional=true}
clickhouse-driver = {version="*", optional=true}
duckdb = {version="^0.6.0", optional=true}
textual = {version="^0.9.1", optional=true}
textual-select = {version="*", optional=true}

[tool.poetry.dev-dependencies]
parameterized = "*"
Expand All @@ -63,6 +65,7 @@ trino = ["trino"]
clickhouse = ["clickhouse-driver"]
vertica = ["vertica-python"]
duckdb = ["duckdb"]
tui = ["textual", "textual-select"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
11 changes: 11 additions & 0 deletions sqeleton/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,16 @@ def repl(database):
return repl_main(database)


CONN_EDITOR_HELP = """CONFIG_PATH - Path to a TOML config file of db connections, new or existing."""


@main.command(no_args_is_help=True, help=CONN_EDITOR_HELP)
@click.argument("config_path", required=True)
def conn_editor(config_path):
from .conn_editor import main

return main(config_path)


if __name__ == "__main__":
main()
Loading