01Quick start
Open a file, create a table, insert, query. Values come back as real Python objects.
02Connect & cursors
A connection is a database file. Use it as a context manager so it always closes.
Tip: use one connection per thread — the engine is single-writer.
03Insert & parameters
Bind values with ? placeholders (never string-format SQL). None becomes SQL NULL; executemany loads many rows fast.
04Fetching rows
Step row-by-row, in batches, or all at once. description gives the column names.
05Rows as dicts
A tiny helper turns rows into dicts keyed by column name.
06Transactions
Each statement auto-commits. For all-or-nothing batches, wrap them in BEGIN / COMMIT (or ROLLBACK).
07Joins
INNER, LEFT (and two-table RIGHT) joins work as you'd expect.
08Aggregates, GROUP BY, HAVING
COUNT / SUM / AVG / MIN / MAX, with grouping, filtering, and DISTINCT.
09CASE expressions
Both the searched and simple forms, including inside aggregates.
10Subqueries
Scalar subqueries and IN (SELECT …).
11UNION
UNION de-duplicates; UNION ALL keeps duplicates. A trailing ORDER BY applies to the whole result.
12Upserts: REPLACE & ON DUPLICATE KEY UPDATE
Insert-or-update on a PRIMARY KEY / UNIQUE conflict. VALUES(col) refers to the would-be-inserted value; you can also reference the existing row.
13INSERT … SELECT
Populate or archive a table from a query in one statement.
14Indexes, UNIQUE & ALTER TABLE
15Binary data (blobs)
Pass bytes as a parameter; it comes back as bytes.
16Pagination
LIMIT / OFFSET for pages; a separate COUNT for the total.
17Complex example — store analytics
A self-contained mini e-commerce schema, seeded with executemany, then real analytical queries: a three-way join, revenue by category, monthly revenue, and a window-free "top N per group" via a correlated count.
18Use with pandas
Load any query straight into a DataFrame using description for the columns.
19A tiny key-value store
Upserts make a durable dict in ~15 lines.
20Maintenance & durability
PRAGMAs for journal mode, integrity checks, and index repair.
21Error handling
Every failure raises sqlxtralite.Error.
The package is on PyPI — pip install sqlxtralite.
SQL