Kwil v2
Search…
⌃K

Utilities

The Kwil SDK contains utilities to make development easier. This page explores these utilities
The Kwil JS/TS SDK provides enumerators to enable strong typing for various Kwil conventions. The Kwil Types and Utils are exported at the top-level of the Kwil package:

Browser

import { WebKwil, Types, Utils } from 'kwil';

NodeJS

const { NodeKwil, Types, Utils } = require('kwil');
// or
const kwiljs = require('kwil');
// types: kwiljs.Types
// utils: kwiljs.Utils

Types

The Kwil SDK Types provide type safety using enumerators for different Kwil conventions. The SDK has enumerators for:
  • Data Types
  • Attributes
  • Modifiers
  • Queries
  • Comparison Operators
  • Index Types
The Kwil SDK exports enumerators upper cased to make it clear what they are, even to Javascript users. The different enumerators can be accessed within the following namespaces:
import { Types } from 'kwil';
/* types:
{
DataType,
AttributeType,
ModifierType,
QueryType,
OperatorType,
IndexType
}
*/
// example:
const stringDataType = Types.DataType.STRING
// or
const callerModifier = Types.ModifierType.CALLER

Utils

Similar to Types, Kwil Utils are separated into different namespaces. This enables us to add new utilities and expose more internal functionality without cluttering the the Utils namespace.

generateDBID

The generateDBID function is used to generate a database's unique identifier from an owner address and database name:
const dbid = Utils.generateDBID('0xOwner_Address', 'db_name')

UUID

The UUID namespace stores utilities for generating UUIDs. While users are able to pass their own RFC-4122 compliant UUIDs to Kwil, the SDK also provides functionality to generate cryptographically random UUIDs, as well as validate user-generated UUIDs are RFC-4122 compliant:
The Kwil SDK uses RFC-4122 version 4 UUIDs to ensure randomness, as well as to protect user privacy. Other UUID versions contain information that clients may not wish to expose to the public (like a machine's MAC address). Users can use any UUID, but for most cases it is recommended to use the provided function.
const uuid = Utils.UUID.v4()
// to validate a UUID not generated from Kwil:
const otherUUID = '50b4cb1f-51f3-45bc-98d7-0149dd6bb341'
const isValid = Utils.UUID.isRFC4122Compliant(otherUUID);
// isValid = true