Querying Data

Use select() to retrieve rows from a table. It always returns a list of dictionaries, one per row.

db.select(table, where=None, order=None)

Parameters

Parameter Type Description
table str Name of the table
where dict or str Optional filter. Dict keys are ANDed together; or pass a raw SQL string.
order str Optional SQL clause appended after WHERE (ORDER BY, LIMIT, etc.)

Select all rows

products = db.select('products')

for p in products:
    print(p['name'], p['price'])

Filter with a dictionary

Multiple keys are joined with AND:

# WHERE category = 'electronics' AND in_stock = 1
results = db.select('products', {'category': 'electronics', 'in_stock': 1})

Filter with a SQL string

results = db.select('products', "price < 100")

results = db.select('products', "name LIKE '%cable%'")

Ordering and limiting results

# 10 most expensive products
top10 = db.select('products', order='ORDER BY price DESC LIMIT 10')

# Page 2 (rows 11–20)
page2 = db.select('products', order='ORDER BY id ASC LIMIT 10, 10')

# Combined filter + order
recent = db.select('orders', "status = 'pending'", order='ORDER BY created_at DESC LIMIT 5')

Return value

Always returns a list of dicts. If no rows match, returns an empty list [].

row = db.select('users', {'email': '[email protected]'})

if row:
    print(row[0]['name'])   # first (and likely only) match
else:
    print("User not found")

Next step

Update existing records →