SQLite dialect plugin for SQLRules (REGEXP helpers and JSON).
Project description
sqlrules-sqlite
SQLite dialect plugin for SQLRules.
Install
pip install sqlrules-sqlite
Usage
import sqlite3
from typing import Annotated, Any
from pydantic import BaseModel, Field
from sqlalchemy import Column, MetaData, String, Table, create_engine, text
from sqlrules import Compiler, JsonContains, JsonHasKey
from sqlrules_sqlite import SQLitePlugin, register_regexp
class RowFilter(BaseModel):
name: Annotated[str, Field(pattern=r"^A")]
meta: Annotated[dict[str, Any], JsonContains({"active": True}), JsonHasKey("active")]
table = Table(
"rows",
MetaData(),
Column("name", String),
Column("meta", String),
)
compiler = Compiler(plugins=[SQLitePlugin()], dialect="sqlite")
rules = compiler.compile(RowFilter, table)
engine = create_engine("sqlite://")
with engine.raw_connection() as conn:
# SQLAlchemy 2 may wrap the DBAPI connection; unwrap if needed.
dbapi = conn.driver_connection if hasattr(conn, "driver_connection") else conn
register_regexp(dbapi)
Operators
| IR operator | Notes |
|---|---|
pattern |
column REGEXP pattern; call register_regexp(connection) |
type_check |
typeof / REGEXP shape checks; text forms need register_regexp |
json_contains |
JSON1 json_extract equality for object keys |
json_has_key |
json_type(column, '$.key') IS NOT NULL |
Case-insensitive patterns (re.IGNORECASE / PatternSpec.ignore_case) are
encoded with a (?i) prefix understood by register_regexp.
Security note
register_regexp installs a Python re.search UDF. Untrusted
Field(pattern=...) values can cause CPU denial of service (ReDoS) in
your process — not SQL injection. Prefer static/allowlisted patterns. See
SECURITY.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlrules_sqlite-1.0.1.tar.gz.
File metadata
- Download URL: sqlrules_sqlite-1.0.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60b464ed6e389f2fc41ff40ba9aa56193f38a3661e503cb0720f0092af3a98bb
|
|
| MD5 |
bdb9862a9ae34859b9eef26d40121b82
|
|
| BLAKE2b-256 |
306f9ee0da498d0ff087ff39ad88788459188d2277da7dda0b2d50566ef062e4
|
File details
Details for the file sqlrules_sqlite-1.0.1-py3-none-any.whl.
File metadata
- Download URL: sqlrules_sqlite-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff955bd6946af455cad0fd2770c1956a77940cf56cfe52a39c668832583fa4d0
|
|
| MD5 |
2f2b472a680ae9a17013dd52482521af
|
|
| BLAKE2b-256 |
c5712f18be6931695ac7b8eec06306c0d3e8f891f60e6a32f278d38bb55e7f06
|