AppDBDocsOpen console

Documentation DBL guide

Getting started

Build a notebook database. Define a table, expose operations, and generate a client from the same source.

Install the tools

Use the Linux x86-64 tools archive on a glibc-based system. It contains dbl for formatting and generating clients, appdb for database administration, and appdbctl for your organization.

Shell · install and verify
curl -fsSLO https://docs.appdb.cloud/downloads/appdb-tools-linux-amd64.tar.gz
curl -fsSLO https://docs.appdb.cloud/downloads/appdb-tools-linux-amd64.tar.gz.sha256
sha256sum -c appdb-tools-linux-amd64.tar.gz.sha256
mkdir -p "$HOME/.local/bin"
tar -xzf appdb-tools-linux-amd64.tar.gz -C "$HOME/.local/bin"
export PATH="$HOME/.local/bin:$PATH"

Start with a package

Save the complete notebook.dbl example in a working directory. A package can include several DBL files. A file’s namespace qualifies its declarations. Inside the same namespace, refer to them by their short names.

Shell · download the working example
curl -fsSLO https://docs.appdb.cloud/dbl/examples/notebook.dbl
notebook.dbl · a table
namespace notebook;

table Book {
    id: UInt8,
    slug: Text,
    primary key(id),
    unique index by_slug {
        key: (slug),
        value: {id},
    },
}

Put each field on its own line in declarations and record literals. A trailing comma belongs before a newline. Inline index keys and projections use (slug) and {id}. In an expression or type, the comma in a one-element tuple such as (id,) identifies the tuple. Run dbl fmt notebook.dbl to apply this layout.

Every book has a numeric primary key. The unique index also reserves its slug, so two books cannot claim the same one. The full package adds notes that reference their book.

Expose an operation

notebook.dbl · create and read
export write fn create_book(id: UInt8, slug: Text) -> () {
    Book.insert({
        id: id,
        slug: slug,
    });
}

export fn lookup(id: UInt8) -> Text? {
    return Note.get(id)?.body;
}

A client can call notebook::create_book with an ID and slug. It can call notebook::lookup with a note ID and receive the body or null if the note does not exist.

Check the source and generate a client

Shell · Python client
dbl fmt --check notebook.dbl
dbl generate --lang python --out generated notebook.dbl

The generator checks the package and writes generated/client.py. An invalid field or return type produces a diagnostic with a source location. To run these calls, provision a database and activate the same package.

Explore the guide

  • Types and values

    Choose types for stored fields, arguments, and results. The declaration determines what the database accepts and what a generated client sends.

  • Tables and constraints

    Define the rows your application stores and the invariants each write must preserve.

  • Functions and transactions

    Give clients named operations. The function signature describes the input and result, and the body defines the transaction.

  • Queries and indexes

    Start from a primary key or declare an index for the order and fields a query needs.

  • Deploy and retire versions

    Plan against a database, stage a candidate, and activate it. Clients bind to an active package version.

  • Identity and permissions

    Define a role, mint a token, and check permissions for an operation.

  • Built-in operations

    Look up signatures and examples for DBL built-in operations.