Kwil v2

Syntax Overview

Getting Started with Kuneiform

Basic Syntax

The Kuneiform syntax allows you to define your database, tables, and actions (i.e. queries) in a single file.
// Basic Kuneiform Syntax
database <NAME>;
table <NAME> {<COLUMN list>}
table ...
action <NAME> (<PARAMETER list>) <public/private> { <raw SQLite sql> }
action ...

Database Statement

At the top of your Kuneiform file, you should write your database statement. Note that the statement must be followed by a semicolon.
database my_social_dapp;

Table Declaration

The part of the Kuneiform syntax is table declarations. This allows you to define each table in the database, and the columns and indexes associated with the database. More information on the table declaration, as well as the column types, modifiers, and indexes, are found in Table Overview.
Unlike the database statement, table declarations are NOT followed by a semicolon.
table users {
id int primary, //id column
name text notnull, //name column
username text notnull, //username column
wallet text notnull, //wallet column
#wallet_index index(wallet) //b-tree index on wallet column

Action Declaration

The last part of the Kuneiform syntax is your action declarations. Actions are prepared SQL statements that can be executed on your database. Within the action body, you can define nearly any SQL query (except for non-deterministic functions and cartesian joins). More information on the action declaration can be found in the Action Overview.
Similar to the table declaration, action declarations are NOT followed by a semicolon.
action add_user($id, $name, $username) public {
INSERT INTO users (id, name username, wallet)
VALUES ($id, $name, $username, @caller)