Skip to main content

Query APIs

WeaveDB queries cover most of the things Firestore can do with syntactic sugar inspired by Firestore Sweet.


To get the next nonce for an address. Nonces are internally used for signature verification to write data.

await db.getNonce("address")

get / cget

get only returns data, whereas cget returns metadata of the docs too.

{ id, setter, data, block: { height, timestamp } }

The metadata returned with cget functions as a cursor for pagination.

Get a doc

await db.get("collection_name", "doc_id")
await db.cget("collection_name", "doc_id")

Get a collection

await db.get("collection_name")
await db.cget("collection_name")

Arbitrary length of document nesting is possible.

await db.get("collection_name", "doc_id", "sub_collection_name_1", "sub_doc_id_1", "sub_collection_name_2", "sub_doc_id_2")

Limit the number of docs

await db.get("collection_name", 5)


await db.get("collection_name", [ "age" ])
await db.get("collection_name", [ "age", "desc" ])
await db.get("collection_name", [ "age", "desc" ], [ "name", "asc" ])


await db.get("collection_name", ["age"], [ "age", ">", 20 ])

= > >= < <= != in not-in array-contains array-contains-any are supported.


await db.get("collection_name", [ "age" ], [ "startAfter", 20 ], [ "endAt", 60 ])
await db.get("collection_name", [ "age" ], [ "name", "desc" ], [ "startAfter", 20, "Bob" ])

startAt startAfter endAt endAfter are supported.


const docs_page1 = db.cget("collection_name", [ "age" ])
const docs_page2 = db.cget("collection_name", [ "age" ], ["startAfter", docs_page1[docs_page1.length - 1]])


Add a doc

await db.add({ "age": 20, "name": "Bob" }, "collection_name")

The doc id will be randomly yet deterministically assigned.


To get the last added doc id, use getIds.

const tx = await db.add({ "age": 20, "name": "Bob" }, "collection_name")
const doc_id = await db.getIds(tx))[0]


Set a doc

await db.set({ "age": 20, "name": "Bob" }, "collection_name", "doc_id")


Upsert a doc

await db.upsert({ "age": 20, "name": "Bob" }, "collection_name", "doc_id")


Update a doc

await db.update({ "age": 25 }, "collection_name", "doc_id")

Delete a field

await db.update({ "age": db.del() }, "collection_name", "doc_id")

Increase/Decrease a field

await db.update({ "age": }, "collection_name", "doc_id")
await db.update({ "age": }, "collection_name", "doc_id")

Array union

await db.update({ "chars": db.union([ "a", "b", "c", "d" ]) }, "collection_name", "doc_id")

Array remove

await db.update({ "chars": db.union([ "b", "c" ]) }, "collection_name", "doc_id")

Set block timestamp

await db.update({ "date": db.ts() }, "collection_name", "doc_id")

Set signer Ethereum address

await db.update({ "address": db.signer() }, "collection_name", "doc_id")


Delete a doc

await db.delete("collection_name", "doc_id")


Atomic batch write

await db.batch([
["set", { name: "Bob" }, "people", "Bob"],
["upsert", { name: "Alice" }, "people", "Alice"],
["delete", "John"]