Kwil Database Builder Tour

Luke Lamey
Kwil
Published in
6 min readMar 7, 2023

Please Note: The Database Builder has been deprecated as of the Kuneiform Release. Please use the Kuneiform IDE to deploy your Kwil database.

As part of the recent Kwil Alpha release, we are excited to announce a new user interface for building on Kwil: The Kwil Database Builder.

If you would like a video tour of the database, check out the video below!
https://www.youtube.com/watch?v=H8wPGV0tyC0

Kwil is a network for developing scalable, permissionless, decentralized relational databases. As we build new ways for users to deploy databases on Kwil, we want to ensure that there is a tool that is easy and accessible to all Kwil users, regardless of language preference or development experience. Furthermore, we know that many Kwil users are rapidly iterating on their own products, so we want to create an environment where developers and product teams can rapidly iterate and prototype their database too. Thus, we created the Kwil database builder, an easy-to-use frontend for deploying new databases and viewing database metadata.

The Kwil database builder serves two purposes for Kwil users:

  1. Deploy New Databases on the Kwil Network.
  2. View existing database metadata on the Kwil Network.

Deploying New Databases

To deploy a new database on Kwil through the database builder, begin by connecting your wallet and adding Kwil Testnet tokens (if you need testnet tokens, check out the Kwil testnet faucet). Note that funds must be approved before they can be deposited and made available. You can read more about ERC-20 approvals here.

Approving and depositing testnet funds

Once funds are deposited, you can enter the database building mode. Click the “Create Database +” button and type your desired database name.

Creating a new database called “demo_db”

The next step is to create your tables. Toggle over to the table tab and select “Create Table +.” Within the table interface, you can add columns, queries, and indexes.

Let’s begin by making columns. Click the green “+” button to open up a modal to create a column. Currently, Kwil supports five column types: String, INT64, INT32, Boolean, and UUID. On each column, you can add any required attributes to be applied to the column. For example, you can set that a column’s contents must have a minimum length of seven characters; thus, the network will not all any inserts or updates on that column that are not at least seven characters long. More information on the variable and attribute types supported on Kwil can be found in our documentation.

Adding an ID column with the primary key attribute
Creating a new table with three columns

Once a table is created, the next step is to make the queries that can be executed on the table. Click the “Add Query Button” to open up the query interface.

Currently, developers can define insert, update, and delete queries that will govern the CUD operations for your database. As you create your query, you can see the corresponding SQL statement that is being made based on the defined parameters and where predicates.

Kwil also introduces the concept of modifiers that Web 3.0 developers will find helpful for their decentralized applications. Currently, Kwil supports a “Caller” modifier, which will “call” the user’s wallet address when they sign a transaction and automatically include that wallet as an input in the query. The caller modifier functions similarly to Solidity’s msg.sender functionality.

The caller modifier is useful for controlling access to update and delete queries. For example, say you only want to let users update database records containing their wallet address in a specific column. To do this, you can define an update query with a caller modifier in your where clause. When the query is executed and signed by the user’s wallet, the database will look for records with the corresponding user’s wallet address. Thus, the user can only update records containing their wallet address in the specified column. You can see the caller modifier in action in our SDK demo.

An example update query with a caller modifier on the wallet column

The last step in creating your table is to add an index. Kwil supports multi-column indexes on single tables. You can read more about indexes on Kwil in our documentation.

A sample binary tree index on the wallet column

Once all your tables are created, the last step is to create roles for the database. Within each role, you can assign which of your previously defined queries the role can execute. Currently, Kwil has two types of roles: default and non-default. Default roles can be used by any user, whereas non-default roles can only be used by the wallet that created the database. Because anyone can use default roles, it is important to ensure that caller modifiers are configured so malicious users cannot execute unwanted updates on deletes on your tables. The Kwil team is actively considering more ways to provision role-based access control (e.g., NFT / token ownership, DAO membership, etc.). If you have feedback on how you would like to see roles provisioned, don't hesitate to get in touch with us at help@kwil.com.

Two new queries for the database

Once your roles have been completed, the last step is to compile and deploy your database. The compile button checks the inputs of your database to ensure that none of your inputs violate any validation rules. If the database compiles successfully, you will see a brief summary of your database. You can alter your database and then click the compile button again if any changes need to be made. If everything looks good, click the deploy button to launch your database on Kwil. Once your database successfully deploys, it will be live on the Kwil network!

New database successfully deployed!

Reading Database Metadata

In addition to deploying new databases, the Kwil database builder lets you see the metadata for your existing databases.

The layout follows the same flow as the deploy interface. On the database tab, you can select which database you want to view. On the table tab, you can see more details regarding each table in the selected database. On the role tab, you can view the roles on the database and which queries each role can execute.

Table metadata for database already deployed on Kwil

Reading your database metadata is particularly useful when executing queries and reading Kwil data into your application. For example, if you are executing an insert, update, or delete query, you can use the Kwil database builder to view the query input names. Although the Kwil SDK also contains functionality to view table metadata, the database builder is a quick and easy-to-use tool that accelerates your development when building on Kwil.

Looking to the Future

At Kwil, we have many plans for new ways to interact with the Kwil network. These include new frontend tools for visualizing and exploring Kwil data, new developer SDKs, and other tools for easily integrating Kwil into your application.

As we build these new features, we are always looking for further feedback to help guide their priority, structure, and utility. If you are building with a decentralized relational database and want to help shape the future of Web 3.0 structured data, please don’t hesitate to reach out to us on Twitter @KwilTeam or by email at help@kwil.com.

--

--