Skip to main content

The sqlite connector supports read and writing to/from a sqlite database.

Tabset

Read​

Import data from a SQLite Database

Recipe​

read:
- sqlite:
database: './tests/test.db'
command: SELECT * from my_table

Function​

from wrangles.connectors import sqlite
df = sqlite.read(
database = './tests/test.db',
command = 'SELECT * from my_table'
)

Parameters​

ParameterRequiredData TypeNotes
database✓strThe database to connect to including the file path. e.g. directory/database.db
command✓strTable name or SQL command to select data. Note - using variables here can make your recipe vulnerable to sql injection. Use params if using variables from untrusted sources.
ifstrA condition that will determine whether the action runs or not as a whole.

Write​

Export data to a SQLite Database

Recipe​

write:
- sqlite:
database: './sample/fake.db'
table: my_table

Function​

from wrangles.connectors import sqlite
sqlite.write(
df = df,
database = './sample/fake.db',
table = 'my_table'
)

Parameters​

ParameterRequiredData TypeNotes
df✓DataFrameFunction only. DataFrame of contents to write to the database. Columns must match the target schema. By default, if the target table doesn't exist, it will be created.
database✓strThe database to connect to including the file path. e.g. directory/database.db
table✓strThe table to write to
ifstrA condition that will determine whether the action runs or not as a whole.

Run​

Run a command on a SQLite Database.

Recipe​

run:
on_start:
- sqlite:
database: './sample/my_db.db'
command: CREATE TABLE test_table_copy AS SELECT * FROM test_table

Function​

from wrangles.connectors import sqlite
sqlite.run(
database = './temp/fake.db',
command = 'CREATE TABLE test_table_copy AS SELECT * FROM test_table'
)

Parameters​

ParameterRequiredData TypeNotes
database✓strThe database to connect to including the file path. e.g. directory/database.db
command✓str, listSQL command or a list of SQL commands to execute
paramslist, objVariables to pass to a parameterized query. This may use %s or %(name)s syntax
ifstrA condition that will determine whether the action runs or not as a whole.