🗂️ SQL Connectors¶
Meerschaum's first-class connector is the SQLConnector
. Several built-in sql
connectors are defined by default:
Connector | Description | URI |
---|---|---|
sql:main (default) |
The pre-configured TimescaleDB instance included in the Meerschaum Stack. It corresponds to a database running on localhost and is therefore shared amongst environments. |
postgresql+psycopg://mrsm:mrsm@localhost:5432/meerschaum |
sql:local |
A SQLite file within the Meerschaum root directory. Because sql:local is contained in the root directory, it is isolated between environments. |
sqlite:///$MRSM_ROOT_DIR/sqlite/mrsm_local.db |
sql:memory |
An in-memory SQLite database. This is not persistent and is isolated per-process. | sqlite:///:memory: |
Add new connectors with bootstrap connectors
or by setting environment variables.
Supported Flavors¶
The following database flavors are confirmed to be feature-complete through the Meerschaum test suite and are listed in descending order of compatability and performance.
- TimescaleDB
- PostgreSQL
- Citus
- SQLite
- MariaDB
- MySQL 5.7+
- DuckDB
- Microsoft SQL Server (2016+ recommended)
- Oracle SQL
In-place Syncs¶
When a pipe has the same fetch and instance connectors, syncing will occur entirely within the database context through SQL. As such, this is a high-performance method to incrementally materialize views.
Inplace syncing example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
Utility Functions¶
If you work closely with relational databases, you may find the SQLConnector
very useful. See below for several handy functions that Meerschaum provides:
SQLConnector
Methods¶
read()
¶
Pass the name of a table or a SQL query into SQLConnector.read()
to fetch a Pandas DataFrame.
1 2 3 4 5 6 |
|
read()
also supports server-side cursors, allowing you to efficiently stream chunks from the result set:
1 2 3 4 5 6 7 8 9 10 |
|
to_sql()
¶
Wrapper around pandas.DataFrame.to_sql()
. Persist your dataframes directly to tables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
exec()
¶
Execute SQL queries directly and return the SQLAlchemy result. This is useful for queries without result sets, like DROP
, ALTER
, CREATE
, UPDATE
, INSERT
, etc., as well as executing stored procedures.
1 2 3 4 5 6 7 8 |
|
exec_queries()
¶
A safer option to execute multiple queries is passing a list to SQLConnector.exec_queries()
. The flag break_on_error
will roll back the transaction if any of the provided queries fail.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
meerschaum.utils.sql
Functions¶
🚧 This section is still under construction ― code snippets will be added soon!