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 🙏

© 2024 – Pkg Stats / Ryan Hefner

libsql

v0.5.0-pre.5

Published

A better-sqlite3 compatible API for libSQL that supports Bun, Deno, and Node

Downloads

357,058

Readme

libSQL API for JavaScript/TypeScript

npm Ask AI

libSQL is an open source, open contribution fork of SQLite. This source repository contains libSQL API bindings for Node, which aims to be compatible with better-sqlite3, but with opt-in promise API.

Please note that there is also the libSQL SDK, which is useful if you don't need better-sqlite3 compatibility or use libSQL in environments like serverless functions that require fetch()-based database access protocol.

Features

  • In-memory and local libSQL/SQLite databases
  • Remote libSQL databases
  • Embedded, in-app replica that syncs with a remote libSQL database
  • Supports Bun, Deno, and Node on macOS, Linux, and Windows.

Installing

You can install the package with:

Node:

npm i libsql

Bun:

bun add libsql

Deno:

Use the npm: prefix for package import:

import Database from 'npm:libsql';

Documentation

Getting Started

To try out your first libsql program, type the following in hello.js:

import Database from 'libsql';

const db = new Database(':memory:');

db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");
db.exec("INSERT INTO users (id, name, email) VALUES (1, 'Alice', '[email protected]')");

const row = db.prepare("SELECT * FROM users WHERE id = ?").get(1);

console.log(`Name: ${row.name}, email: ${row.email}`);

and then run:

$ node hello.js

To use the promise API, import libsql/promise:

import Database from 'libsql/promise';

const db = new Database(':memory:');

await db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");
await db.exec("INSERT INTO users (id, name, email) VALUES (1, 'Alice', '[email protected]')");

const stmt = await db.prepare("SELECT * FROM users WHERE id = ?");
const row = stmt.get(1);

console.log(`Name: ${row.name}, email: ${row.email}`);

Connecting to a local database file

import Database from 'libsql';

const db = new Database('hello.db');

Connecting to a Remote libSQL server

import Database from 'libsql';

const url = process.env.LIBSQL_URL;
const authToken = process.env.LIBSQL_AUTH_TOKEN;

const opts = {
  authToken: authToken,
};

const db = new Database(url, opts);

Creating an in-app replica and syncing it

import libsql

const opts = { syncUrl: "<url>", authToken: "<optional auth token>" };
const db = new Database('hello.db', opts);
db.sync();

Creating a table

db.exec("CREATE TABLE users (id INTEGER, email TEXT);")

Inserting rows into a table

db.exec("INSERT INTO users VALUES (1, '[email protected]')")

Querying rows from a table

const row = db.prepare("SELECT * FROM users WHERE id = ?").get(1);

Developing

To build the libsql package, run:

LIBSQL_JS_DEV=1 npm run build

You can then run the integration tests with:

export LIBSQL_JS_DEV=1
npm link
cd integration-tests
npm link libsql
npm test

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in libSQL by you, shall be licensed as MIT, without any additional terms or conditions.