Skip to main content

Quickstart

This guide outlines the basic usage of the Kwil CLI for configuring a private key, provider, chain ID, and deploying a database. It will also demonstrate how to execute an action and call a view action.

Prerequisites

Make sure that you have downloaded and installed kwil-cli onto your system. Refer to the installation guide for detailed instructions.

Configuration

Persistent Configuration

Configure the Kwil CLI with a persistent global setting using the command below, which will prompt you for the necessary configurations:

kwil-cli configure

Your configuration file will be stored at ~/.kwil-cli/config.json.

Global Flags

For temporary use, you can override persistent configurations by using global flags like so:

kwil-cli --provider=http://your.kwil.provider:port --private-key=your_private_key --chain-id=your_chain_id

Global flags take precedence over persistent configs.

Executing SQL

To execute a raw SQL statement (e.g. to create a table), use the kwil-cli exec-sql command:

kwil-cli exec-sql --sql "CREATE TABLE users (id INT PRIMARY KEY, username TEXT NOT NULL UNIQUE, age INT NOT NULL, address TEXT NOT NULL UNIQUE)"
note

The exec-sql command is only for executing SQL statements that are modifying state, and can not be used to read data.

Executing an Action

Execute an action against a database by providing the action name and parameters. For example, if we have an action called create_user, and it takes parameters of username (of type text) and age (of type int8), you can execute it like so:

kwil-cli exec-action create_user text:satoshi int8:32

Reading Data with a SELECT Statement

To execute a SELECT statement on a database, use the kwil-cli query command:

kwil-cli query --sql "SELECT * FROM users"

Reading Data with a View Action

To call a view (read-only) action on a database, use the kwil-cli call-action command. For example, if we have a view action called get_user, and it takes a parameter of username (of type text), you can call it like so:

kwil-cli call-action get_user text:satoshi