# table

Tables of JSON rows — insert, put, get, update, delete, list, find and count.

```js
import { table } from 'wisp';
const orders = table('orders');   // async methods
```

```python
from wisp import table
orders = table("orders")          # synchronous methods
```

Guide: [Tables](/tables). Table names: lowercase letters, digits and `_`.

## insert(row)

Adds a row with a new time-ordered `id`, `createdAt` and `updatedAt`. Returns the stored row.

```js
const o = await orders.insert({ customer: 'ada@example.com', total: 42 });
```

## put(id, row)

Creates or replaces the row with your own id. Returns the stored row.

## get(id)

The row, or `null` / `None`.

## update(id, patch)

Merges `patch` into the row and returns it, or `null` / `None` when the row doesn't exist. Not atomic.

```python
orders.update(o["id"], {"status": "paid"})
```

## delete(id)

Deletes the row.

## list(options?)

Rows in insertion order: `{ rows, cursor }`.

```js
const { rows, cursor } = await orders.list({ limit: 50 });
```
```python
page = orders.list(limit=50, cursor=None)
```

## find(where?, options?)

Rows matching `where` — an object of fields to compare for equality, or a function that returns true for rows to keep.

| Option (JS) | Python | Description |
| --- | --- | --- |
| `limit` | `limit=100` | Maximum rows |
| `orderBy` | `order_by=None` | Field to sort by |
| `desc` | `desc=False` | Sort descending |

```js
const big = await orders.find((o) => o.total > 100, { orderBy: 'total', desc: true, limit: 10 });
```
```python
open_orders = orders.find({"status": "open"}, order_by="createdAt", desc=True)
```

## count(where?)

The number of matching rows.

## Limits

Rows up to 256 KB. `find` and `count` scan up to 10,000 rows.
