npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kwildb-query-builder

v0.1.3

Published

A SQL query builder for KwilDB

Downloads

2

Readme

KwilDB-Query-Builder

  • A SQL query builder for KwilDB.
  • Built on top of Knex.js.
  • Built-in typescript support

Installation

npm install kwildb-query-builder

Initialization

import { readFileSync } from "fs";
import { KwilDB } from "kwildb-query-builder";

let privateKey = JSON.parse(readFileSync("./privateKey.json").toString());
let secret = "LT|UllzAI~.V-10!ITC&nf#IV;KJV6Tk";

const kwildb = new KwilDB({
  host: "test-db.kwil.xyz",
  protocol: "https",
  moat: "testdemo",
  privateKey: privateKey,
  secret,
});

Documentation

browse Documentation

Schema and Table builder

// create and drop schema

kwildb.createSchema(schemaName: string, sync = true)

kwildb.dropSchema(schemaName: string, cascade?: boolean, sync = true) 

kwildb.dropSchemaIfExists(
    schemaName: string,
    cascade?: boolean,
    sync = true
  )


// create and drop table

kwildb.createTable(
    tableName: string,
    builder: (tableBuilder: Knex.CreateTableBuilder) => any,
    schemaName?: string,
    sync = true
  ) 

kwildb.dropTable(tableName: string, sync = true)

kwildb.dropTableIfExists(tableName: string, sync = true)

Example

const kwildb = new KwilDB({
  host: "test-db.kwil.xyz",
  protocol: "https",
  moat: "testdemo",
  privateKey: privateKey,
  secret,
});  


// create a table
// second argument is a callback function to modify the table's structure using the knex.js schema-building commands.
await kwildb.createTable("users",(builder) => {
    builder.increments("id"),
    builder.string("name"),
    builder.integer("age")
  },"testSchema")


// drop a schema
await kwildb.dropSchema("testSchema")

look at knex.js Schema Builder page for more info

QueryBuilder

kwildb.query(tableName: string, schemaName?: string, sync = false)

Example

const kwildb = new KwilDB({
  host: "test-db.kwil.xyz",
  protocol: "https",
  moat: "testdemo",
  privateKey: privateKey,
  secret,
});


// For read queries except execute() and first() methods you have to end the method chain with execute() method to run it.
const result = await kwildb.query("users", "testSchema").select("name").whereNull("age").execute()


await kwildb.query("users").insert([
    {
        name: "test1",
    },
    {
        name: "test2",
    },
], true);

Supported methods

list of all available methods except execute() and first() methods are available at query builder documentation page

Syntax

Syntax of all available methods is the same as knex.js query builder syntax.

you can find knex.js query builder documentation page at http://knexjs.org/guide/query-builder

execute, first Query builder methods

execute

execute(sync?: boolean)

For read queries except first() method , you have to end the method chain with execute() method to run it.

const result = await kwildb.query("users").max("age as a").execute()

first

The select queries always return an array of objects, even when the query is intended to fetch a single row. However, using the first method will give you the first row or null (when there are no rows).

const user = await kwildb.query("users").where("id",1).first()
if (user) {
    console.log(user)
}

Raw Query

kwildb.rawQuery(query: string, sync = false)
kwildb.preparedStatement(query: string, values: any[], sync = false)

License

Available under the MIT license. See the LICENSE file for more info.