Skip to navigation

SQLite Connector

View as Markdown

SQLite is what lets development and CI exercise the full sampling path, including SQL sampling, with no credentials. There are two ways to use it: sample in place with SQLiteSource, or read a table into memory with read().

Installation

pip install "structured-data-models-client[relational,sqlite]"

Sample in place with SQLiteSource

import adbc_driver_sqlite.dbapi
from sdm_client import PredictiveQuery, Schema
from sdm_connectors import SQLiteSource
connection = adbc_driver_sqlite.dbapi.connect("data.db")
source = SQLiteSource(connection)
schema = Schema.from_source(source, {"users": "USERS", "orders": "ORDERS"})
request = PredictiveQuery(
"PREDICT COUNT(orders.*, 0, 30, days) FOR EACH users.user_id", schema
).materialize(indices=[7, 12, 3])

tables maps the names your query uses to the names in the database; leave it out to describe every table SQLite holds, under its own name. The connection is yours — close it when you are done sampling.

Read into memory instead

from sdm_connectors import read
from sdm_client import Schema
users = read("sqlite", database="data.db", table="USERS")
orders = read("sqlite", database="data.db", table="ORDERS")
schema = Schema.from_data({"users": users, "orders": orders})

database and uri are aliases for the same argument; pass exactly one. Pass query= instead of table= to read the result of an arbitrary SQL statement.

Review the inferred schema and relationships before predicting — see Build a Schema.