Socket
Socket
Sign inDemoInstall

libsql-stateless-easy

Package Overview
Dependencies
2
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.2.0

24

lib-cjs/builders.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchReqStepExecCondBuilder = exports.BatchReqStepsBuilder = exports.SQLStatementBuilder = exports.SQLValueBuilder = void 0;
exports.libsqlBatchReqStepExecCondBuilder = exports.libsqlBatchReqStepsBuilder = exports.libsqlStatementBuilder = exports.libsqlValueBuilder = void 0;
const js_base64_1 = require("js-base64");
//========================================================
function SQLValueBuilder(value) {
function libsqlValueBuilder(value) {
if (value === null)

@@ -19,5 +19,5 @@ return { type: "null" };

}
exports.SQLValueBuilder = SQLValueBuilder;
exports.libsqlValueBuilder = libsqlValueBuilder;
//========================================================
function SQLStatementBuilder(s) {
function libsqlStatementBuilder(s) {
if (typeof (s) !== "string")

@@ -28,3 +28,3 @@ if (Object.prototype.toString.call(s.args) === '[object Array]') {

for (let i = 0; i < _args.length; i++)
p_args.push(SQLValueBuilder(_args[i]));
p_args.push(libsqlValueBuilder(_args[i]));
return {

@@ -40,3 +40,3 @@ sql: s.sql,

for (const key in _args)
p_named_args.push({ name: key, value: SQLValueBuilder(_args[key]) });
p_named_args.push({ name: key, value: libsqlValueBuilder(_args[key]) });
return {

@@ -52,15 +52,15 @@ sql: s.sql,

}
exports.SQLStatementBuilder = SQLStatementBuilder;
exports.libsqlStatementBuilder = libsqlStatementBuilder;
//===========================================================
function BatchReqStepsBuilder(batch_queries) {
function libsqlBatchReqStepsBuilder(batch_queries) {
let p_stmts = [];
for (let i = 0; i < batch_queries.length; i++)
p_stmts.push({ stmt: SQLStatementBuilder(batch_queries[i]) });
p_stmts.push({ stmt: libsqlStatementBuilder(batch_queries[i]) });
return p_stmts;
}
exports.BatchReqStepsBuilder = BatchReqStepsBuilder;
exports.libsqlBatchReqStepsBuilder = libsqlBatchReqStepsBuilder;
//===========================================================
function BatchReqStepExecCondBuilder(c) {
function libsqlBatchReqStepExecCondBuilder(c) {
return c;
}
exports.BatchReqStepExecCondBuilder = BatchReqStepExecCondBuilder;
exports.libsqlBatchReqStepExecCondBuilder = libsqlBatchReqStepExecCondBuilder;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.libsqlClient = void 0;
exports.createClient = void 0;
const simple_functions_1 = require("./simple_functions");
class libsqlClient {
conf;
checkServerOnRun;
constructor(conf, checkServerOnRun) {
constructor(conf) {
this.conf = conf;
this.checkServerOnRun = checkServerOnRun;
}
async execute(stmt) {
if (this.checkServerOnRun &&
!(await this.serverOk()))
throw Error("Server is not compatible with `libsql-stateless`");
return await (0, simple_functions_1.libsqlExecute)(this.conf, stmt);
}
async batch(steps) {
if (this.checkServerOnRun &&
!(await this.serverOk()))
throw Error("Server is not compatible with `libsql-stateless`");
return await (0, simple_functions_1.libsqlBatch)(this.conf, steps);

@@ -28,2 +20,5 @@ }

}
exports.libsqlClient = libsqlClient;
function createClient(conf) {
return new libsqlClient(conf);
}
exports.createClient = createClient;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.libsqlBatchStreamResParser = exports.libsqlStatementResParser = exports.SQLValueParser = void 0;
exports.libsqlBatchStreamResParser = exports.libsqlStatementResParser = exports.libsqlValueParser = void 0;
const js_base64_1 = require("js-base64");
//========================================================
function SQLValueParser(value) {
function libsqlValueParser(value) {
if (value.type === "null")

@@ -19,3 +19,3 @@ return null;

}
exports.SQLValueParser = SQLValueParser;
exports.libsqlValueParser = libsqlValueParser;
//========================================================

@@ -47,3 +47,3 @@ //from hrana-client-ts/src/result.ts

for (let j = 0; j < res.rows[i].length; j++) {
const value = SQLValueParser(res.rows[i][j]);
const value = libsqlValueParser(res.rows[i][j]);
Object.defineProperty(row, j, { value });

@@ -50,0 +50,0 @@ const colName = res.cols[j].name;

@@ -8,3 +8,3 @@ "use strict";

async function libsqlExecute(conf, stmt) {
const res = await (0, libsql_stateless_1.libsqlExecute)(conf, (0, builders_1.SQLStatementBuilder)(stmt));
const res = await (0, libsql_stateless_1.libsqlExecute)(conf, (0, builders_1.libsqlStatementBuilder)(stmt));
if (res.isOk)

@@ -19,3 +19,3 @@ return (0, parsers_1.libsqlStatementResParser)(res.val);

for (let i = 0; i < steps.length; i++)
_steps.push({ stmt: (0, builders_1.SQLStatementBuilder)(steps[i]) });
_steps.push({ stmt: (0, builders_1.libsqlStatementBuilder)(steps[i]) });
const res = await (0, libsql_stateless_1.libsqlBatch)(conf, _steps);

@@ -22,0 +22,0 @@ if (res.isOk)

import { rawSQLStatement, rawValue } from './types';
import { libsqlBatchReqStep, libsqlBatchReqStepExecCond, libsqlSQLStatement, libsqlSQLValue } from 'libsql-stateless';
export declare function SQLValueBuilder(value: rawValue): libsqlSQLValue;
export declare function SQLStatementBuilder(s: rawSQLStatement): libsqlSQLStatement;
export declare function BatchReqStepsBuilder(batch_queries: Array<rawSQLStatement>): Array<libsqlBatchReqStep>;
export declare function BatchReqStepExecCondBuilder(c: {
export declare function libsqlValueBuilder(value: rawValue): libsqlSQLValue;
export declare function libsqlStatementBuilder(s: rawSQLStatement): libsqlSQLStatement;
export declare function libsqlBatchReqStepsBuilder(batch_queries: Array<rawSQLStatement>): Array<libsqlBatchReqStep>;
export declare function libsqlBatchReqStepExecCondBuilder(c: {
type: "ok";

@@ -8,0 +8,0 @@ step: number;

import { Base64 } from 'js-base64';
//========================================================
export function SQLValueBuilder(value) {
export function libsqlValueBuilder(value) {
if (value === null)

@@ -17,3 +17,3 @@ return { type: "null" };

//========================================================
export function SQLStatementBuilder(s) {
export function libsqlStatementBuilder(s) {
if (typeof (s) !== "string")

@@ -24,3 +24,3 @@ if (Object.prototype.toString.call(s.args) === '[object Array]') {

for (let i = 0; i < _args.length; i++)
p_args.push(SQLValueBuilder(_args[i]));
p_args.push(libsqlValueBuilder(_args[i]));
return {

@@ -36,3 +36,3 @@ sql: s.sql,

for (const key in _args)
p_named_args.push({ name: key, value: SQLValueBuilder(_args[key]) });
p_named_args.push({ name: key, value: libsqlValueBuilder(_args[key]) });
return {

@@ -49,11 +49,11 @@ sql: s.sql,

//===========================================================
export function BatchReqStepsBuilder(batch_queries) {
export function libsqlBatchReqStepsBuilder(batch_queries) {
let p_stmts = [];
for (let i = 0; i < batch_queries.length; i++)
p_stmts.push({ stmt: SQLStatementBuilder(batch_queries[i]) });
p_stmts.push({ stmt: libsqlStatementBuilder(batch_queries[i]) });
return p_stmts;
}
//===========================================================
export function BatchReqStepExecCondBuilder(c) {
export function libsqlBatchReqStepExecCondBuilder(c) {
return c;
}
import { libsqlConfig } from "libsql-stateless";
import { rawSQLStatement } from "./types";
export declare class libsqlClient {
declare class libsqlClient {
private readonly conf;
private readonly checkServerOnRun;
constructor(conf: libsqlConfig, checkServerOnRun: boolean);
constructor(conf: libsqlConfig);
execute(stmt: rawSQLStatement): Promise<import("./types").ResultSet>;

@@ -11,1 +10,3 @@ batch(steps: Array<rawSQLStatement>): Promise<import("./types").ResultSet[]>;

}
export declare function createClient(conf: libsqlConfig): libsqlClient;
export {};
import { libsqlBatch, libsqlExecute, libsqlServerCompatCheck } from "./simple_functions";
export class libsqlClient {
class libsqlClient {
conf;
checkServerOnRun;
constructor(conf, checkServerOnRun) {
constructor(conf) {
this.conf = conf;
this.checkServerOnRun = checkServerOnRun;
}
async execute(stmt) {
if (this.checkServerOnRun &&
!(await this.serverOk()))
throw Error("Server is not compatible with `libsql-stateless`");
return await libsqlExecute(this.conf, stmt);
}
async batch(steps) {
if (this.checkServerOnRun &&
!(await this.serverOk()))
throw Error("Server is not compatible with `libsql-stateless`");
return await libsqlBatch(this.conf, steps);

@@ -25,1 +17,4 @@ }

}
export function createClient(conf) {
return new libsqlClient(conf);
}
import { libsqlBatchStreamResOkData, libsqlSQLValue, libsqlStatementResOkData } from "libsql-stateless";
import { ResultSet, rawValue } from "./types";
export declare function SQLValueParser(value: libsqlSQLValue): rawValue;
export declare function libsqlValueParser(value: libsqlSQLValue): rawValue;
export declare function libsqlStatementResParser(res: libsqlStatementResOkData): ResultSet;
export declare function libsqlBatchStreamResParser(res: libsqlBatchStreamResOkData): Array<ResultSet>;
import { Base64 } from "js-base64";
//========================================================
export function SQLValueParser(value) {
export function libsqlValueParser(value) {
if (value.type === "null")

@@ -42,3 +42,3 @@ return null;

for (let j = 0; j < res.rows[i].length; j++) {
const value = SQLValueParser(res.rows[i][j]);
const value = libsqlValueParser(res.rows[i][j]);
Object.defineProperty(row, j, { value });

@@ -45,0 +45,0 @@ const colName = res.cols[j].name;

import { libsqlExecute as LIBlibsqlExecute, libsqlBatch as LIBlibsqlBatch, libsqlServerCompatCheck as LIBlibsqlServerCompatCheck } from "libsql-stateless";
import { SQLStatementBuilder } from "./builders";
import { libsqlStatementBuilder } from "./builders";
import { libsqlBatchStreamResParser, libsqlStatementResParser } from "./parsers";
export async function libsqlExecute(conf, stmt) {
const res = await LIBlibsqlExecute(conf, SQLStatementBuilder(stmt));
const res = await LIBlibsqlExecute(conf, libsqlStatementBuilder(stmt));
if (res.isOk)

@@ -14,3 +14,3 @@ return libsqlStatementResParser(res.val);

for (let i = 0; i < steps.length; i++)
_steps.push({ stmt: SQLStatementBuilder(steps[i]) });
_steps.push({ stmt: libsqlStatementBuilder(steps[i]) });
const res = await LIBlibsqlBatch(conf, _steps);

@@ -17,0 +17,0 @@ if (res.isOk)

{
"name": "libsql-stateless-easy",
"version": "1.0.3",
"version": "1.2.0",
"homepage": "https://github.com/DaBigBlob/libsql-stateless-easy#readme",

@@ -24,5 +24,6 @@ "repository": {

},
"authors": [
"DaBigBlob <localboxcrox@gmail.com>"
],
"author": {
"name": "LocalBox Crox",
"email": "localboxcrox@gmail.com"
},
"description": "this makes using libsql-stateless easy",

@@ -58,3 +59,3 @@ "files": [

"test": "bun run _tests/test2.ts",
"test2": "bun run _tests/test3.ts",
"test4": "bun run _tests/test4.ts",
"clean": "npm run prebuild",

@@ -67,4 +68,4 @@ "prod": "npm publish && npm run clean"

"js-base64": "^3.7.5",
"libsql-stateless": "^2.5.6"
"libsql-stateless": "^2.5.9"
}
}
# libsql-stateless-easy
## under works
> A wrapper for `libsql-stateless` that provides a much better DX
- ✅ **Supported runtime environments:** Web API (browser, serverless), Bun, Node.js (>=18)
- ✅ **Is built for:** Quick stateless query execution. (Mainly for serverless and edge functions.)
- ⚠️ Supports everything in `@libsql/client` **except (explicit) `transactions` and local or in-memory DBs.**
- ✅ **The API provided by `libsql-stateless-easy` is simple** and (almost) exactly the same as `@libsql/client`.
- ⚠️ `libsql-stateless-easy` comes with the cost of (computational and memory) overheads potentially unneeded by you. But is still very very very slim compared to `@libsql/client`.
<br>
**For much better performance, consider using [`libsql-stateless`](https://github.com/DaBigBlob/libsql-stateless) instead**: it, however, has a pretty raw and explicit API unappreciated by many developers.
# Installation
```sh
$ npm i libsql-stateless-easy #pnpm, yarn, etc.
# or
$ bun add libsql-stateless-easy
```
# Client Usage
`libsql-stateless-client`'s `client` has the *same* semantics as [`@libsql/client/web`](https://docs.turso.tech/libsql/client-access/javascript-typescript-sdk#create-a-database-client-object-for-local-and-remote-access)
```ts
import { createClient } from "libsql-stateless-easy";
//or
const { createClient } = require("libsql-stateless-easy");
const client = createClient({
db_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","moca@doro.co","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.serverOk();
if (res3) console.log("Server Compat Check OK");
else console.error("Server Compat Check NOT OK");
```
# This Documentation is incomplete
I'll complete it when I have more time.
### List of other stuff in this library
Feel free to explore them (or even contribute to the documentation!)
```ts
import {
libsqlValueBuilder, libsqlStatementBuilder, libsqlBatchReqStepsBuilder,
libsqlBatchReqStepExecCondBuilder, libsqlValueParser, libsqlStatementResParser,
libsqlBatchStreamResParser,
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
createClient //used above
} from "libsql-stateless-easy";
```
# TODO (roadmap)
- Add drizzle ORM support
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc