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-stateless-easy

v1.8.0

Published

thin libSQL stateless http driver for TypeScript and JavaScript but easy

Downloads

8,172,072

Readme

libsql-stateless-easy

Thin libSQL stateless HTTP driver for TypeScript and JavaScript for the edge but easy 🚀

  • Supported runtime environments: Web API (browser, serverless), Bun, Node.js (>=18)
  • Is extremely light: 8.3kB (unpacked)* / 3.5kB (gzipped)
  • Is built for: Quick stateless query execution. (Mainly for serverless and edge functions.)
  • ✅ Supports everything in @libsql/client/web **except interactive transactions.
  • Is Atomic and stateless, every function performs complete execution in exactly 1 roundtrip.
  • libsql-stateless-easy is simply a drop-in replacement and exactly same API as @libsql/client/web.

* The actual js that is included with your project. (Excluding the type definitions and 2 copies of the main js for esm and cjs. (because you're gonna use one of them))
**Interactive transactions are not supported because this lib is stateless but transactions are supported.

Installation

$ npm i libsql-stateless-easy #pnpm, yarn, etc.
# or
$ bun add libsql-stateless-easy

Client Usage

libsql-stateless-easy's client has the exact same API as @libsql/client/web's client.

    import { createClient } from "libsql-stateless-easy";
    //or
    const { createClient } = require("libsql-stateless-easy");

    const client = createClient({
        url: "https://da-fish-mandible.turso.io",
        authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg"
    });
    
    const res = await client.batch([
        {
            sql: "select * from contacts where contact_id = ?;",
            args: [3]
        },
        "select first_name, last_name, email from contacts where contact_id = 2",
        {
            sql: "insert into contacts (contact_id,first_name,last_name,email,phone) values (?,?,?,?,?);",
            args: [6,"glomm","feru","[email protected]","001"]
        },
        {
            sql: "delete from contacts where contact_id = :kkl",
            args: {kkl: 6}
        }
    ]);
    console.log(res);

    const res2 = await client.execute({
        sql: "select first_name, last_name, email, contact_id from contacts where contact_id = ?;",
        args: [1]
    });
    console.log(res2);

    const res3 = await client.execute("select first_name, last_name, email, contact_id from contacts where contact_id = 1;");
    console.log(res3);

Drizzle (and other ORMs)

libsql-stateless-easy's client works with drizzle (and other ORMs) out-of-the-box. This library implements the same Interface is the official client and therefore works with all the ORMs that the official client works with.

    import { createClient } from "libsql-stateless-easy";
    import { drizzle } from 'drizzle-orm/libsql';

    const client = createClient({
        url: "https://da-fish-mandible.turso.io",
        authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg"
    });

    const db = drizzle(client);

    const result = await db.select().from(table_name).all();
    console.log(result);
  • This library has the same LibsqlError codes as @libsql/client

Performance

This library checks your configs, environments and server compatibility by default.
However this is kinda resource intensive if you're creating client instances often.
So, IF YOU ARE SURE YOUR CONFIGURATION, ENVIRONMENT AND SERVER VERSION ARE CORRECT, PLEASE DISABLE THE CHECKS FOR EVEN BETTER PERFORMANCE.

    const client = createClient({
        url: "https://da-fish-mandible.turso.io",
        authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg",
        disableCriticalChecks: true
    });

Custom Fetch

Pass your own implementation of fetch or fetch-like function if you don't want libsql-stateless-easy to use the global fetch or if your global fetch does not exist.

    import { createClient, libsqlFetchLike } from 'libsql-stateless-easy';

    const client = createClient({
        url: "https://da-fish-mandible.turso.io",
        authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg",
        fetch: async (...args: Parameters<libsqlFetchLike>): ReturnType<libsqlFetchLike> => {
            //implement your own fetch here (look at examples/custom_fetch for concrete example)
            /** NOTE:
             * args[0] is the url string
             * args[1] is the request init
             */
        }
    });

    const res = await client.execute("select * from contacts;");
    console.log(res);

Modularity

libsql-stateless-easy is extremely modular. execute, batch, etc. can be used without initiating a client.

    import { libsqlBatchTransaction, libsqlExecute } from "libsql-stateless-easy";
    //or
    const { libsqlBatchTransaction, libsqlExecute } = require("libsql-stateless-easy");

    const config = {
        url: "https://da-fish-mandible.turso.io",
        authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg"
    };
    
    const res = await libsqlBatchTransaction(
        config,
        [
            {
                sql: "select * from contacts where contact_id = ?;",
                args: [3]
            },
            "select first_name, last_name, email from contacts where contact_id = 2",
            {
                sql: "insert into contacts (contact_id,first_name,last_name,email,phone) values (?,?,?,?,?);",
                args: [6,"glomm","feru","[email protected]","001"]
            },
            {
                sql: "delete from contacts where contact_id = :kkl",
                args: {kkl: 6}
            }
        ]
    );
    console.log(res);

    const res2 = await libsqlExecute(
        config,
        {
            sql: "select first_name, last_name, email, contact_id from contacts where contact_id = ?;",
            args: [1]
        }
    );
    console.log(res2);

    const res3 = await libsqlExecute(config, "select first_name, last_name, email, contact_id from contacts where contact_id = 1;", []);
    console.log(res3);

libsql-stateless-easy's client just conveniently packages these individually executable functions to conform to the official sdk interface.

List of other stuff in this library

Feel free to explore them (however you don't need to as they've been neatly packaged into the client)

    import {
        libsqlValueBuilder, libsqlArgumentsBuilder, libsqlStatementBuilder, libsqlBatchReqStepsBuilder, libsqlBatchReqStepExecCondBuilder, libsqlTransactionBeginStatement,
        libsqlValueParser, libsqlStatementResParser, libsqlBatchStreamResParser, libsqlTransactionBatchStreamResParser,
        libsqlExecute, //has easier API than `libsql-stateless`'s function of the same name
        libsqlBatch, //has easier API than `libsql-stateless`'s function of the same name
        libsqlServerCompatCheck, //has easier API than `libsql-stateless`'s function of the same name,
        libsqlBatchTransaction, libsqlExecuteMultiple
        createClient //used above
    } from "libsql-stateless-easy";

API Level

NOTE: current API level is that of latest stable libsql-stateless.
Read this section.