Tableland is a SQL database supporting on-chain data processes.
Today’s smart contracts are complicated. They support more complex applications. Smart contracts need to store, query, and process more complicated and larger data. Smart contracts are highly coupled with data. Thus these complicated data process scenarios make smart contracts complex and hard to maintain. Developers need to add data-related logic to their contracts, like data queries, data updates, and data filtering. For different data structures, developers need to write different functions.
Besides extra complexity, another problem is flexibility. When developers need to query data with complex filters, developers need to add custom query functions to the contracts. Developers cannot directly read and filter the data.
In the Web2 world, the database takes all data-related work. Applications store clean and structured data in the database. Developers can read desired data with SQL. Data are decoupled with applications.
Tableland is born to solve these problems. Tableland call itself, Web3 native database.
Because on-chain data storage is expansive, Tableland uses the off-chain database and on-chain smart contracts for privilege checks and data modification.
Dapp smart contracts send data update requests to Tableland smart contracts
Tableland smart contracts check the caller’s privilege and emit events with query
Tableland off-chain validator network monitor on-chain event and execute SQL
Sync Tableland off-chain validator network
function runSQL(
address caller,
uint256 tableId,
string memory statement
) external payable override whenNotPaused nonReentrant {
if (
!_exists(tableId) ||
!(caller == _msgSenderERC721A() || owner() == _msgSenderERC721A())
) {
revert Unauthorized();
}
uint256 querySize = bytes(statement).length;
if (querySize > QUERY_MAX_SIZE) {
revert MaxQuerySizeExceeded(querySize, QUERY_MAX_SIZE);
}
emit RunSQL(
caller,
ownerOf(tableId) == caller,
tableId,
statement,
_getPolicy(caller, tableId)
);
}
Although developers can use smart contracts to execute SQL, dapp smart contracts cannot get any return values. This hurts composability.
Tableland solves this problem with a dapp frontend, dapp smart contracts, and Tableland three parties interaction. The dapp frontend reads data and dapp smart contracts update data.
Dapp frontend reads data from Tableland gateway. Tableland gateway can directly interact with Tableland off-chain validator network. The function of the Tableland gateway is similar to the function of blockchain RPC. With the gateway, developers don’t need to build their own network nodes.
If the dapp frontend sends a data update request to the gateway, the gateway will relay the request to the Tableland smart contacts.
As a "Web3 native database", Tableland still has lots of limitations:
CREATE TABLE
, INSERT
, UPDATE
, DELETE
, SELECT
, GRANT
, REVOKE
INT
, REAL
, TEXT
, BLOB
, ANY
Tableland names itself "Web3 native database". This is a little exaggerated because of the bad composability between contracts and data. Now Tableland can be applied to games and NFT.
Tableland has great support for NFT. After creating the table and inserting NFT metadata, developers get a gateway link. Developers can use this link as URI.
function _baseURI() internal pure override returns (string memory) {
return "https://testnet.tableland.network/chain/5/tables/79/id/";
}
Later developers can use Tableland CLI to update NFT metadata.
Tableland will release its NFT in July. NFT holders can access more development functions. In the future, Tableland will make improvements in the following areas:
Tableland is not the end of the Web3 native database. A truly Web3 native database should satisfy the following requirements:
If your project satisfies the above points, feel free to DM me on Twitter.