Gathering detailed insights and metrics for libsql-stateless-easy
Gathering detailed insights and metrics for libsql-stateless-easy
Gathering detailed insights and metrics for libsql-stateless-easy
Gathering detailed insights and metrics for libsql-stateless-easy
Thin libSQL stateless HTTP driver for TypeScript and JavaScript for the edge but easy 🚀
npm install libsql-stateless-easy
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
63 Stars
411 Commits
3 Forks
1 Branches
2 Contributors
Updated on 06 Nov 2024
TypeScript (97.13%)
Shell (1.64%)
JavaScript (1.23%)
Cumulative downloads
Total Downloads
Last day
-72.2%
15
Compared to previous day
Last week
-37.5%
163
Compared to previous week
Last month
-34.8%
8,171,967
Compared to previous month
Last year
6,753,840.7%
221,326,636
Compared to previous year
1
3
Thin libSQL stateless HTTP driver for TypeScript and JavaScript for the edge but easy 🚀
@libsql/client/web
**except interactive transactions
.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.
1$ npm i libsql-stateless-easy #pnpm, yarn, etc. 2# or 3$ bun add libsql-stateless-easy
libsql-stateless-easy
's client
has the exact same API as @libsql/client/web
's client
.
1 import { createClient } from "libsql-stateless-easy"; 2 //or 3 const { createClient } = require("libsql-stateless-easy"); 4 5 const client = createClient({ 6 url: "https://da-fish-mandible.turso.io", 7 authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg" 8 }); 9 10 const res = await client.batch([ 11 { 12 sql: "select * from contacts where contact_id = ?;", 13 args: [3] 14 }, 15 "select first_name, last_name, email from contacts where contact_id = 2", 16 { 17 sql: "insert into contacts (contact_id,first_name,last_name,email,phone) values (?,?,?,?,?);", 18 args: [6,"glomm","feru","moca@doro.co","001"] 19 }, 20 { 21 sql: "delete from contacts where contact_id = :kkl", 22 args: {kkl: 6} 23 } 24 ]); 25 console.log(res); 26 27 const res2 = await client.execute({ 28 sql: "select first_name, last_name, email, contact_id from contacts where contact_id = ?;", 29 args: [1] 30 }); 31 console.log(res2); 32 33 const res3 = await client.execute("select first_name, last_name, email, contact_id from contacts where contact_id = 1;"); 34 console.log(res3);
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.
1 import { createClient } from "libsql-stateless-easy"; 2 import { drizzle } from 'drizzle-orm/libsql'; 3 4 const client = createClient({ 5 url: "https://da-fish-mandible.turso.io", 6 authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg" 7 }); 8 9 const db = drizzle(client); 10 11 const result = await db.select().from(table_name).all(); 12 console.log(result);
LibsqlError
codes as @libsql/client
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.
1 const client = createClient({ 2 url: "https://da-fish-mandible.turso.io", 3 authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg", 4 disableCriticalChecks: true 5 });
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.
1 import { createClient, libsqlFetchLike } from 'libsql-stateless-easy'; 2 3 const client = createClient({ 4 url: "https://da-fish-mandible.turso.io", 5 authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg", 6 fetch: async (...args: Parameters<libsqlFetchLike>): ReturnType<libsqlFetchLike> => { 7 //implement your own fetch here (look at examples/custom_fetch for concrete example) 8 /** NOTE: 9 * args[0] is the url string 10 * args[1] is the request init 11 */ 12 } 13 }); 14 15 const res = await client.execute("select * from contacts;"); 16 console.log(res);
libsql-stateless-easy
is extremely modular. execute
, batch
, etc. can be used without initiating a client
.
1 import { libsqlBatchTransaction, libsqlExecute } from "libsql-stateless-easy"; 2 //or 3 const { libsqlBatchTransaction, libsqlExecute } = require("libsql-stateless-easy"); 4 5 const config = { 6 url: "https://da-fish-mandible.turso.io", 7 authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg" 8 }; 9 10 const res = await libsqlBatchTransaction( 11 config, 12 [ 13 { 14 sql: "select * from contacts where contact_id = ?;", 15 args: [3] 16 }, 17 "select first_name, last_name, email from contacts where contact_id = 2", 18 { 19 sql: "insert into contacts (contact_id,first_name,last_name,email,phone) values (?,?,?,?,?);", 20 args: [6,"glomm","feru","moca@doro.co","001"] 21 }, 22 { 23 sql: "delete from contacts where contact_id = :kkl", 24 args: {kkl: 6} 25 } 26 ] 27 ); 28 console.log(res); 29 30 const res2 = await libsqlExecute( 31 config, 32 { 33 sql: "select first_name, last_name, email, contact_id from contacts where contact_id = ?;", 34 args: [1] 35 } 36 ); 37 console.log(res2); 38 39 const res3 = await libsqlExecute(config, "select first_name, last_name, email, contact_id from contacts where contact_id = 1;", []); 40 console.log(res3);
libsql-stateless-easy
's client
just conveniently packages these individually executable functions to conform to the official sdk interface.
Feel free to explore them (however you don't need to as they've been neatly packaged into the client
)
1 import { 2 libsqlValueBuilder, libsqlArgumentsBuilder, libsqlStatementBuilder, libsqlBatchReqStepsBuilder, libsqlBatchReqStepExecCondBuilder, libsqlTransactionBeginStatement, 3 libsqlValueParser, libsqlStatementResParser, libsqlBatchStreamResParser, libsqlTransactionBatchStreamResParser, 4 libsqlExecute, //has easier API than `libsql-stateless`'s function of the same name 5 libsqlBatch, //has easier API than `libsql-stateless`'s function of the same name 6 libsqlServerCompatCheck, //has easier API than `libsql-stateless`'s function of the same name, 7 libsqlBatchTransaction, libsqlExecuteMultiple 8 createClient //used above 9 } from "libsql-stateless-easy";
NOTE: current API level is that of latest stable libsql-stateless.
Read this section.
No vulnerabilities found.
No security vulnerabilities found.