Initial commit: New MoreminiMore website with fresh design
This commit is contained in:
22
node_modules/libsql/LICENSE
generated
vendored
Normal file
22
node_modules/libsql/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Joshua Wise
|
||||
Copyright (c) 2023 Pekka Enberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
171
node_modules/libsql/README.md
generated
vendored
Normal file
171
node_modules/libsql/README.md
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
# libSQL API for JavaScript/TypeScript
|
||||
|
||||
[](https://badge.fury.io/js/libsql)
|
||||
[](https://www.phorm.ai/query?projectId=3c9a471f-4a47-469f-81f6-4ea1ff9ab418)
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **Turso database and libSQL are two different projects from the same team.**
|
||||
>
|
||||
> **libSQL** (this repository) is an open-source fork of SQLite. It extends SQLite with features like embedded replicas and remote access, but inherits SQLite's fundamental limitations such as the single-writer model.
|
||||
>
|
||||
> **[Turso database](https://github.com/tursodatabase/turso)** is a SQLite-compatible database rewritten from scratch in Rust. It is **not** a fork of SQLite — it is a completely new implementation that goes beyond what any SQLite fork can offer, including concurrent writes and bi-directional sync with offline support. Turso is currently in beta.
|
||||
>
|
||||
> **If you're starting a new project, you probably want to look into [Turso](https://github.com/tursodatabase/turso).** libSQL is actively maintained, but new features are being developed in Turso.
|
||||
|
||||
[libSQL](https://github.com/libsql/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](https://github.com/WiseLibs/better-sqlite3/), but with opt-in promise API.
|
||||
|
||||
## 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:**
|
||||
|
||||
```sh
|
||||
npm i libsql
|
||||
```
|
||||
|
||||
**Bun:**
|
||||
|
||||
```sh
|
||||
bun add libsql
|
||||
```
|
||||
|
||||
**Deno:**
|
||||
|
||||
Use the `npm:` prefix for package import:
|
||||
|
||||
```typescript
|
||||
import Database from 'npm:libsql';
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
* [API reference](docs/api.md)
|
||||
|
||||
## Getting Started
|
||||
|
||||
To try out your first libsql program, type the following in `hello.js`:
|
||||
|
||||
```javascript
|
||||
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', 'alice@example.org')");
|
||||
|
||||
const row = db.prepare("SELECT * FROM users WHERE id = ?").get(1);
|
||||
|
||||
console.log(`Name: ${row.name}, email: ${row.email}`);
|
||||
```
|
||||
|
||||
and then run:
|
||||
|
||||
```shell
|
||||
$ node hello.js
|
||||
```
|
||||
|
||||
To use the promise API, import `libsql/promise`:
|
||||
|
||||
```javascript
|
||||
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', 'alice@example.org')");
|
||||
|
||||
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
|
||||
|
||||
```javascript
|
||||
import Database from 'libsql';
|
||||
|
||||
const db = new Database('hello.db');
|
||||
````
|
||||
|
||||
#### Connecting to a Remote libSQL server
|
||||
|
||||
```javascript
|
||||
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
|
||||
|
||||
```javascript
|
||||
import libsql
|
||||
|
||||
const opts = { syncUrl: "<url>", authToken: "<optional auth token>" };
|
||||
const db = new Database('hello.db', opts);
|
||||
db.sync();
|
||||
```
|
||||
|
||||
#### Creating a table
|
||||
|
||||
```javascript
|
||||
db.exec("CREATE TABLE users (id INTEGER, email TEXT);")
|
||||
```
|
||||
|
||||
#### Inserting rows into a table
|
||||
|
||||
```javascript
|
||||
db.exec("INSERT INTO users VALUES (1, 'alice@example.org')")
|
||||
```
|
||||
|
||||
#### Querying rows from a table
|
||||
|
||||
```javascript
|
||||
const row = db.prepare("SELECT * FROM users WHERE id = ?").get(1);
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
To build the `libsql` package, run:
|
||||
|
||||
```console
|
||||
LIBSQL_JS_DEV=1 npm run build
|
||||
```
|
||||
|
||||
You can then run the integration tests with:
|
||||
|
||||
```console
|
||||
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.
|
||||
|
||||
[MIT license]: https://github.com/libsql/libsql-node/blob/main/LICENSE
|
||||
22
node_modules/libsql/auth.js
generated
vendored
Normal file
22
node_modules/libsql/auth.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Authorization outcome.
|
||||
*
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
* @property {number} ALLOW - Allow access to a resource.
|
||||
* @property {number} DENY - Deny access to a resource and throw an error.
|
||||
*/
|
||||
const Authorization = {
|
||||
/**
|
||||
* Allow access to a resource.
|
||||
* @type {number}
|
||||
*/
|
||||
ALLOW: 0,
|
||||
|
||||
/**
|
||||
* Deny access to a resource and throw an error in `prepare()`.
|
||||
* @type {number}
|
||||
*/
|
||||
DENY: 1,
|
||||
};
|
||||
module.exports = Authorization;
|
||||
441
node_modules/libsql/index.js
generated
vendored
Normal file
441
node_modules/libsql/index.js
generated
vendored
Normal file
@@ -0,0 +1,441 @@
|
||||
"use strict";
|
||||
|
||||
const { load, currentTarget } = require("@neon-rs/load");
|
||||
const { familySync, GLIBC, MUSL } = require("detect-libc");
|
||||
|
||||
function requireNative() {
|
||||
if (process.env.LIBSQL_JS_DEV) {
|
||||
return load(__dirname)
|
||||
}
|
||||
let target = currentTarget();
|
||||
// Workaround for Bun, which reports a musl target, but really wants glibc...
|
||||
if (familySync() == GLIBC) {
|
||||
switch (target) {
|
||||
case "linux-x64-musl":
|
||||
target = "linux-x64-gnu";
|
||||
break;
|
||||
case "linux-arm64-musl":
|
||||
target = "linux-arm64-gnu";
|
||||
break;
|
||||
}
|
||||
}
|
||||
// @neon-rs/load doesn't detect arm musl
|
||||
if (target === "linux-arm-gnueabihf" && familySync() == MUSL) {
|
||||
target = "linux-arm-musleabihf";
|
||||
}
|
||||
return require(`@libsql/${target}`);
|
||||
}
|
||||
|
||||
const {
|
||||
databaseOpen,
|
||||
databaseOpenWithSync,
|
||||
databaseInTransaction,
|
||||
databaseInterrupt,
|
||||
databaseClose,
|
||||
databaseSyncSync,
|
||||
databaseSyncUntilSync,
|
||||
databaseExecSync,
|
||||
databasePrepareSync,
|
||||
databaseDefaultSafeIntegers,
|
||||
databaseAuthorizer,
|
||||
databaseLoadExtension,
|
||||
databaseMaxWriteReplicationIndex,
|
||||
statementRaw,
|
||||
statementIsReader,
|
||||
statementGet,
|
||||
statementRun,
|
||||
statementInterrupt,
|
||||
statementRowsSync,
|
||||
statementColumns,
|
||||
statementSafeIntegers,
|
||||
rowsNext,
|
||||
} = requireNative();
|
||||
|
||||
const Authorization = require("./auth");
|
||||
const SqliteError = require("./sqlite-error");
|
||||
|
||||
function convertError(err) {
|
||||
if (err.libsqlError) {
|
||||
return new SqliteError(err.message, err.code, err.rawCode);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database represents a connection that can prepare and execute SQL statements.
|
||||
*/
|
||||
class Database {
|
||||
/**
|
||||
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} path - Path to the database file.
|
||||
*/
|
||||
constructor(path, opts) {
|
||||
const encryptionCipher = opts?.encryptionCipher ?? "aes256cbc";
|
||||
if (opts && opts.syncUrl) {
|
||||
var authToken = "";
|
||||
if (opts.syncAuth) {
|
||||
console.warn("Warning: The `syncAuth` option is deprecated, please use `authToken` option instead.");
|
||||
authToken = opts.syncAuth;
|
||||
} else if (opts.authToken) {
|
||||
authToken = opts.authToken;
|
||||
}
|
||||
const encryptionKey = opts?.encryptionKey ?? "";
|
||||
const syncPeriod = opts?.syncPeriod ?? 0.0;
|
||||
const readYourWrites = opts?.readYourWrites ?? true;
|
||||
const offline = opts?.offline ?? false;
|
||||
const remoteEncryptionKey = opts?.remoteEncryptionKey ?? "";
|
||||
this.db = databaseOpenWithSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod, readYourWrites, offline, remoteEncryptionKey);
|
||||
} else {
|
||||
const authToken = opts?.authToken ?? "";
|
||||
const encryptionKey = opts?.encryptionKey ?? "";
|
||||
const timeout = opts?.timeout ?? 0.0;
|
||||
const remoteEncryptionKey = opts?.remoteEncryptionKey ?? "";
|
||||
this.db = databaseOpen(path, authToken, encryptionCipher, encryptionKey, timeout, remoteEncryptionKey);
|
||||
}
|
||||
// TODO: Use a libSQL API for this?
|
||||
this.memory = path === ":memory:";
|
||||
this.readonly = false;
|
||||
this.name = "";
|
||||
this.open = true;
|
||||
|
||||
const db = this.db;
|
||||
Object.defineProperties(this, {
|
||||
inTransaction: {
|
||||
get() {
|
||||
return databaseInTransaction(db);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
sync() {
|
||||
return databaseSyncSync.call(this.db);
|
||||
}
|
||||
|
||||
syncUntil(replicationIndex) {
|
||||
return databaseSyncUntilSync.call(this.db, replicationIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a SQL statement for execution.
|
||||
*
|
||||
* @param {string} sql - The SQL statement string to prepare.
|
||||
*/
|
||||
prepare(sql) {
|
||||
try {
|
||||
const stmt = databasePrepareSync.call(this.db, sql);
|
||||
return new Statement(stmt);
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a function that executes the given function in a transaction.
|
||||
*
|
||||
* @param {function} fn - The function to wrap in a transaction.
|
||||
*/
|
||||
transaction(fn) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError("Expected first argument to be a function");
|
||||
|
||||
const db = this;
|
||||
const wrapTxn = (mode) => {
|
||||
return (...bindParameters) => {
|
||||
db.exec("BEGIN " + mode);
|
||||
try {
|
||||
const result = fn(...bindParameters);
|
||||
db.exec("COMMIT");
|
||||
return result;
|
||||
} catch (err) {
|
||||
db.exec("ROLLBACK");
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
const properties = {
|
||||
default: { value: wrapTxn("") },
|
||||
deferred: { value: wrapTxn("DEFERRED") },
|
||||
immediate: { value: wrapTxn("IMMEDIATE") },
|
||||
exclusive: { value: wrapTxn("EXCLUSIVE") },
|
||||
database: { value: this, enumerable: true },
|
||||
};
|
||||
Object.defineProperties(properties.default.value, properties);
|
||||
Object.defineProperties(properties.deferred.value, properties);
|
||||
Object.defineProperties(properties.immediate.value, properties);
|
||||
Object.defineProperties(properties.exclusive.value, properties);
|
||||
return properties.default.value;
|
||||
}
|
||||
|
||||
pragma(source, options) {
|
||||
if (options == null) options = {};
|
||||
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
||||
const simple = options['simple'];
|
||||
const stmt = this.prepare(`PRAGMA ${source}`, this, true);
|
||||
return simple ? stmt.pluck().get() : stmt.all();
|
||||
}
|
||||
|
||||
backup(filename, options) {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
serialize(options) {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
function(name, options, fn) {
|
||||
// Apply defaults
|
||||
if (options == null) options = {};
|
||||
if (typeof options === "function") {
|
||||
fn = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
// Validate arguments
|
||||
if (typeof name !== "string")
|
||||
throw new TypeError("Expected first argument to be a string");
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError("Expected last argument to be a function");
|
||||
if (typeof options !== "object")
|
||||
throw new TypeError("Expected second argument to be an options object");
|
||||
if (!name)
|
||||
throw new TypeError(
|
||||
"User-defined function name cannot be an empty string"
|
||||
);
|
||||
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
aggregate(name, options) {
|
||||
// Validate arguments
|
||||
if (typeof name !== "string")
|
||||
throw new TypeError("Expected first argument to be a string");
|
||||
if (typeof options !== "object" || options === null)
|
||||
throw new TypeError("Expected second argument to be an options object");
|
||||
if (!name)
|
||||
throw new TypeError(
|
||||
"User-defined function name cannot be an empty string"
|
||||
);
|
||||
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
table(name, factory) {
|
||||
// Validate arguments
|
||||
if (typeof name !== "string")
|
||||
throw new TypeError("Expected first argument to be a string");
|
||||
if (!name)
|
||||
throw new TypeError(
|
||||
"Virtual table module name cannot be an empty string"
|
||||
);
|
||||
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
authorizer(rules) {
|
||||
databaseAuthorizer.call(this.db, rules);
|
||||
}
|
||||
|
||||
loadExtension(...args) {
|
||||
databaseLoadExtension.call(this.db, ...args);
|
||||
}
|
||||
|
||||
maxWriteReplicationIndex() {
|
||||
return databaseMaxWriteReplicationIndex.call(this.db)
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a SQL statement.
|
||||
*
|
||||
* @param {string} sql - The SQL statement string to execute.
|
||||
*/
|
||||
exec(sql) {
|
||||
try {
|
||||
databaseExecSync.call(this.db, sql);
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts the database connection.
|
||||
*/
|
||||
interrupt() {
|
||||
databaseInterrupt.call(this.db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the database connection.
|
||||
*/
|
||||
close() {
|
||||
databaseClose.call(this.db);
|
||||
this.open = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle 64-bit integer support.
|
||||
*/
|
||||
defaultSafeIntegers(toggle) {
|
||||
databaseDefaultSafeIntegers.call(this.db, toggle ?? true);
|
||||
return this;
|
||||
}
|
||||
|
||||
unsafeMode(...args) {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Statement represents a prepared SQL statement that can be executed.
|
||||
*/
|
||||
class Statement {
|
||||
constructor(stmt) {
|
||||
this.stmt = stmt;
|
||||
this.pluckMode = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle raw mode.
|
||||
*
|
||||
* @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
|
||||
*/
|
||||
raw(raw) {
|
||||
statementRaw.call(this.stmt, raw ?? true);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle pluck mode.
|
||||
*
|
||||
* @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
|
||||
*/
|
||||
pluck(pluckMode) {
|
||||
this.pluckMode = pluckMode ?? true;
|
||||
return this;
|
||||
}
|
||||
|
||||
get reader() {
|
||||
return statementIsReader.call(this.stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an info object.
|
||||
*/
|
||||
run(...bindParameters) {
|
||||
try {
|
||||
if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
|
||||
return statementRun.call(this.stmt, bindParameters[0]);
|
||||
} else {
|
||||
return statementRun.call(this.stmt, bindParameters.flat());
|
||||
}
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns the first row.
|
||||
*
|
||||
* @param bindParameters - The bind parameters for executing the statement.
|
||||
*/
|
||||
get(...bindParameters) {
|
||||
try {
|
||||
if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
|
||||
return statementGet.call(this.stmt, bindParameters[0]);
|
||||
} else {
|
||||
return statementGet.call(this.stmt, bindParameters.flat());
|
||||
}
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an iterator to the resulting rows.
|
||||
*
|
||||
* @param bindParameters - The bind parameters for executing the statement.
|
||||
*/
|
||||
iterate(...bindParameters) {
|
||||
var rows = undefined;
|
||||
if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
|
||||
rows = statementRowsSync.call(this.stmt, bindParameters[0]);
|
||||
} else {
|
||||
rows = statementRowsSync.call(this.stmt, bindParameters.flat());
|
||||
}
|
||||
const iter = {
|
||||
nextRows: Array(100),
|
||||
nextRowIndex: 100,
|
||||
next() {
|
||||
try {
|
||||
if (this.nextRowIndex === 100) {
|
||||
rowsNext.call(rows, this.nextRows);
|
||||
this.nextRowIndex = 0;
|
||||
}
|
||||
const row = this.nextRows[this.nextRowIndex];
|
||||
this.nextRows[this.nextRowIndex] = undefined;
|
||||
if (!row) {
|
||||
return { done: true };
|
||||
}
|
||||
this.nextRowIndex++;
|
||||
return { value: row, done: false };
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
},
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
},
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an array of the resulting rows.
|
||||
*
|
||||
* @param bindParameters - The bind parameters for executing the statement.
|
||||
*/
|
||||
all(...bindParameters) {
|
||||
try {
|
||||
const result = [];
|
||||
for (const row of this.iterate(...bindParameters)) {
|
||||
if (this.pluckMode) {
|
||||
result.push(row[Object.keys(row)[0]]);
|
||||
} else {
|
||||
result.push(row);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts the statement.
|
||||
*/
|
||||
interrupt() {
|
||||
statementInterrupt.call(this.stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the columns in the result set returned by this prepared statement.
|
||||
*/
|
||||
columns() {
|
||||
return statementColumns.call(this.stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle 64-bit integer support.
|
||||
*/
|
||||
safeIntegers(toggle) {
|
||||
statementSafeIntegers.call(this.stmt, toggle ?? true);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Database;
|
||||
module.exports.Authorization = Authorization;
|
||||
module.exports.SqliteError = SqliteError;
|
||||
90
node_modules/libsql/package.json
generated
vendored
Normal file
90
node_modules/libsql/package.json
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"name": "libsql",
|
||||
"version": "0.5.29",
|
||||
"description": "A better-sqlite3 compatible API for libSQL that supports Bun, Deno, and Node",
|
||||
"os": [
|
||||
"darwin",
|
||||
"linux",
|
||||
"win32"
|
||||
],
|
||||
"cpu": [
|
||||
"x64",
|
||||
"arm64",
|
||||
"wasm32",
|
||||
"arm"
|
||||
],
|
||||
"main": "index.js",
|
||||
"types": "types/index.d.ts",
|
||||
"files": [
|
||||
"auth.js",
|
||||
"index.js",
|
||||
"sqlite-error.js",
|
||||
"promise.js",
|
||||
"types/index.d.ts",
|
||||
"types/promise.d.ts"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./promise": {
|
||||
"types": "./types/promise.d.ts",
|
||||
"default": "./promise.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "cargo test",
|
||||
"debug": "cargo build --message-format=json | npm exec neon dist",
|
||||
"build": "npx tsc && cargo build --message-format=json --release | npm exec neon dist -- --name libsql-js",
|
||||
"cross": "cross build --message-format=json --release | npm exec neon dist -- --name libsql-js -m /target",
|
||||
"pack-build": "neon pack-build",
|
||||
"prepack": "neon install-builds",
|
||||
"postversion": "git push --follow-tags"
|
||||
},
|
||||
"author": "Pekka Enberg <penberg@iki.fi>",
|
||||
"license": "MIT",
|
||||
"neon": {
|
||||
"targets": {
|
||||
"aarch64-apple-darwin": "@libsql/darwin-arm64",
|
||||
"aarch64-unknown-linux-gnu": "@libsql/linux-arm64-gnu",
|
||||
"aarch64-unknown-linux-musl": "@libsql/linux-arm64-musl",
|
||||
"x86_64-apple-darwin": "@libsql/darwin-x64",
|
||||
"x86_64-pc-windows-msvc": "@libsql/win32-x64-msvc",
|
||||
"x86_64-unknown-linux-gnu": "@libsql/linux-x64-gnu",
|
||||
"x86_64-unknown-linux-musl": "@libsql/linux-x64-musl",
|
||||
"arm-unknown-linux-gnueabihf": "@libsql/linux-arm-gnueabihf",
|
||||
"arm-unknown-linux-musleabihf": "@libsql/linux-arm-musleabihf"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tursodatabase/libsql-js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"libsql"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/tursodatabase/libsql-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/tursodatabase/libsql-js",
|
||||
"devDependencies": {
|
||||
"@neon-rs/cli": "^0.0.165",
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@neon-rs/load": "^0.0.4",
|
||||
"detect-libc": "2.0.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@libsql/darwin-arm64": "0.5.29",
|
||||
"@libsql/linux-arm64-gnu": "0.5.29",
|
||||
"@libsql/linux-arm64-musl": "0.5.29",
|
||||
"@libsql/darwin-x64": "0.5.29",
|
||||
"@libsql/win32-x64-msvc": "0.5.29",
|
||||
"@libsql/linux-x64-gnu": "0.5.29",
|
||||
"@libsql/linux-x64-musl": "0.5.29",
|
||||
"@libsql/linux-arm-gnueabihf": "0.5.29",
|
||||
"@libsql/linux-arm-musleabihf": "0.5.29"
|
||||
}
|
||||
}
|
||||
445
node_modules/libsql/promise.js
generated
vendored
Normal file
445
node_modules/libsql/promise.js
generated
vendored
Normal file
@@ -0,0 +1,445 @@
|
||||
"use strict";
|
||||
|
||||
const { load, currentTarget } = require("@neon-rs/load");
|
||||
const { familySync, GLIBC, MUSL } = require("detect-libc");
|
||||
|
||||
// Static requires for bundlers.
|
||||
if (0) {
|
||||
require("./.targets");
|
||||
}
|
||||
|
||||
const Authorization = require("./auth");
|
||||
const SqliteError = require("./sqlite-error");
|
||||
|
||||
function convertError(err) {
|
||||
if (err.libsqlError) {
|
||||
return new SqliteError(err.message, err.code, err.rawCode);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
function requireNative() {
|
||||
if (process.env.LIBSQL_JS_DEV) {
|
||||
return load(__dirname)
|
||||
}
|
||||
let target = currentTarget();
|
||||
// Workaround for Bun, which reports a musl target, but really wants glibc...
|
||||
if (familySync() == GLIBC) {
|
||||
switch (target) {
|
||||
case "linux-x64-musl":
|
||||
target = "linux-x64-gnu";
|
||||
break;
|
||||
case "linux-arm64-musl":
|
||||
target = "linux-arm64-gnu";
|
||||
break;
|
||||
}
|
||||
}
|
||||
// @neon-rs/load doesn't detect arm musl
|
||||
if (target === "linux-arm-gnueabihf" && familySync() == MUSL) {
|
||||
target = "linux-arm-musleabihf";
|
||||
}
|
||||
return require(`@libsql/${target}`);
|
||||
}
|
||||
|
||||
const {
|
||||
databaseOpen,
|
||||
databaseOpenWithSync,
|
||||
databaseInTransaction,
|
||||
databaseInterrupt,
|
||||
databaseClose,
|
||||
databaseSyncAsync,
|
||||
databaseSyncUntilAsync,
|
||||
databaseExecAsync,
|
||||
databasePrepareAsync,
|
||||
databaseMaxWriteReplicationIndex,
|
||||
databaseDefaultSafeIntegers,
|
||||
databaseAuthorizer,
|
||||
databaseLoadExtension,
|
||||
statementRaw,
|
||||
statementIsReader,
|
||||
statementGet,
|
||||
statementRun,
|
||||
statementInterrupt,
|
||||
statementRowsAsync,
|
||||
statementColumns,
|
||||
statementSafeIntegers,
|
||||
rowsNext,
|
||||
} = requireNative();
|
||||
|
||||
/**
|
||||
* Database represents a connection that can prepare and execute SQL statements.
|
||||
*/
|
||||
class Database {
|
||||
/**
|
||||
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} path - Path to the database file.
|
||||
*/
|
||||
constructor(path, opts) {
|
||||
const encryptionCipher = opts?.encryptionCipher ?? "aes256cbc";
|
||||
if (opts && opts.syncUrl) {
|
||||
var authToken = "";
|
||||
if (opts.syncAuth) {
|
||||
console.warn("Warning: The `syncAuth` option is deprecated, please use `authToken` option instead.");
|
||||
authToken = opts.syncAuth;
|
||||
} else if (opts.authToken) {
|
||||
authToken = opts.authToken;
|
||||
}
|
||||
const encryptionKey = opts?.encryptionKey ?? "";
|
||||
const syncPeriod = opts?.syncPeriod ?? 0.0;
|
||||
const offline = opts?.offline ?? false;
|
||||
const remoteEncryptionKey = opts?.remoteEncryptionKey ?? "";
|
||||
this.db = databaseOpenWithSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod, offline, remoteEncryptionKey);
|
||||
} else {
|
||||
const authToken = opts?.authToken ?? "";
|
||||
const encryptionKey = opts?.encryptionKey ?? "";
|
||||
const timeout = opts?.timeout ?? 0.0;
|
||||
const remoteEncryptionKey = opts?.remoteEncryptionKey ?? "";
|
||||
this.db = databaseOpen(path, authToken, encryptionCipher, encryptionKey, timeout, remoteEncryptionKey);
|
||||
}
|
||||
// TODO: Use a libSQL API for this?
|
||||
this.memory = path === ":memory:";
|
||||
this.readonly = false;
|
||||
this.name = "";
|
||||
this.open = true;
|
||||
|
||||
const db = this.db;
|
||||
Object.defineProperties(this, {
|
||||
inTransaction: {
|
||||
get() {
|
||||
return databaseInTransaction(db);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
sync() {
|
||||
return databaseSyncAsync.call(this.db);
|
||||
}
|
||||
|
||||
syncUntil(replicationIndex) {
|
||||
return databaseSyncUntilAsync.call(this.db, replicationIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a SQL statement for execution.
|
||||
*
|
||||
* @param {string} sql - The SQL statement string to prepare.
|
||||
*/
|
||||
prepare(sql) {
|
||||
return databasePrepareAsync.call(this.db, sql).then((stmt) => {
|
||||
return new Statement(stmt);
|
||||
}).catch((err) => {
|
||||
throw convertError(err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a function that executes the given function in a transaction.
|
||||
*
|
||||
* @param {function} fn - The function to wrap in a transaction.
|
||||
*/
|
||||
transaction(fn) {
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError("Expected first argument to be a function");
|
||||
|
||||
const db = this;
|
||||
const wrapTxn = (mode) => {
|
||||
return async (...bindParameters) => {
|
||||
await db.exec("BEGIN " + mode);
|
||||
try {
|
||||
const result = fn(...bindParameters);
|
||||
await db.exec("COMMIT");
|
||||
return result;
|
||||
} catch (err) {
|
||||
await db.exec("ROLLBACK");
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
const properties = {
|
||||
default: { value: wrapTxn("") },
|
||||
deferred: { value: wrapTxn("DEFERRED") },
|
||||
immediate: { value: wrapTxn("IMMEDIATE") },
|
||||
exclusive: { value: wrapTxn("EXCLUSIVE") },
|
||||
database: { value: this, enumerable: true },
|
||||
};
|
||||
Object.defineProperties(properties.default.value, properties);
|
||||
Object.defineProperties(properties.deferred.value, properties);
|
||||
Object.defineProperties(properties.immediate.value, properties);
|
||||
Object.defineProperties(properties.exclusive.value, properties);
|
||||
return properties.default.value;
|
||||
}
|
||||
|
||||
pragma(source, options) {
|
||||
if (options == null) options = {};
|
||||
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
||||
const simple = options['simple'];
|
||||
return this.prepare(`PRAGMA ${source}`, this, true).then(async (stmt) => {
|
||||
return simple ? await stmt.pluck().get() : await stmt.all();
|
||||
});
|
||||
}
|
||||
|
||||
backup(filename, options) {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
serialize(options) {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
function(name, options, fn) {
|
||||
// Apply defaults
|
||||
if (options == null) options = {};
|
||||
if (typeof options === "function") {
|
||||
fn = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
// Validate arguments
|
||||
if (typeof name !== "string")
|
||||
throw new TypeError("Expected first argument to be a string");
|
||||
if (typeof fn !== "function")
|
||||
throw new TypeError("Expected last argument to be a function");
|
||||
if (typeof options !== "object")
|
||||
throw new TypeError("Expected second argument to be an options object");
|
||||
if (!name)
|
||||
throw new TypeError(
|
||||
"User-defined function name cannot be an empty string"
|
||||
);
|
||||
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
aggregate(name, options) {
|
||||
// Validate arguments
|
||||
if (typeof name !== "string")
|
||||
throw new TypeError("Expected first argument to be a string");
|
||||
if (typeof options !== "object" || options === null)
|
||||
throw new TypeError("Expected second argument to be an options object");
|
||||
if (!name)
|
||||
throw new TypeError(
|
||||
"User-defined function name cannot be an empty string"
|
||||
);
|
||||
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
table(name, factory) {
|
||||
// Validate arguments
|
||||
if (typeof name !== "string")
|
||||
throw new TypeError("Expected first argument to be a string");
|
||||
if (!name)
|
||||
throw new TypeError(
|
||||
"Virtual table module name cannot be an empty string"
|
||||
);
|
||||
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
authorizer(rules) {
|
||||
databaseAuthorizer.call(this.db, rules);
|
||||
}
|
||||
|
||||
loadExtension(...args) {
|
||||
databaseLoadExtension.call(this.db, ...args);
|
||||
}
|
||||
|
||||
maxWriteReplicationIndex() {
|
||||
return databaseMaxWriteReplicationIndex.call(this.db)
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a SQL statement.
|
||||
*
|
||||
* @param {string} sql - The SQL statement string to execute.
|
||||
*/
|
||||
exec(sql) {
|
||||
return databaseExecAsync.call(this.db, sql).catch((err) => {
|
||||
throw convertError(err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts the database connection.
|
||||
*/
|
||||
interrupt() {
|
||||
databaseInterrupt.call(this.db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the database connection.
|
||||
*/
|
||||
close() {
|
||||
databaseClose.call(this.db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle 64-bit integer support.
|
||||
*/
|
||||
defaultSafeIntegers(toggle) {
|
||||
databaseDefaultSafeIntegers.call(this.db, toggle ?? true);
|
||||
return this;
|
||||
}
|
||||
|
||||
unsafeMode(...args) {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Statement represents a prepared SQL statement that can be executed.
|
||||
*/
|
||||
class Statement {
|
||||
constructor(stmt) {
|
||||
this.stmt = stmt;
|
||||
this.pluckMode = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle raw mode.
|
||||
*
|
||||
* @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
|
||||
*/
|
||||
raw(raw) {
|
||||
statementRaw.call(this.stmt, raw ?? true);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle pluck mode.
|
||||
*
|
||||
* @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
|
||||
*/
|
||||
pluck(pluckMode) {
|
||||
this.pluckMode = pluckMode ?? true;
|
||||
return this;
|
||||
}
|
||||
|
||||
get reader() {
|
||||
return statementIsReader.call(this.stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an info object.
|
||||
*/
|
||||
run(...bindParameters) {
|
||||
try {
|
||||
if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
|
||||
return statementRun.call(this.stmt, bindParameters[0]);
|
||||
} else {
|
||||
return statementRun.call(this.stmt, bindParameters.flat());
|
||||
}
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns the first row.
|
||||
*
|
||||
* @param bindParameters - The bind parameters for executing the statement.
|
||||
*/
|
||||
get(...bindParameters) {
|
||||
try {
|
||||
if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
|
||||
return statementGet.call(this.stmt, bindParameters[0]);
|
||||
} else {
|
||||
return statementGet.call(this.stmt, bindParameters.flat());
|
||||
}
|
||||
} catch (e) {
|
||||
throw convertError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an iterator to the resulting rows.
|
||||
*
|
||||
* @param bindParameters - The bind parameters for executing the statement.
|
||||
*/
|
||||
async iterate(...bindParameters) {
|
||||
var rows = undefined;
|
||||
if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
|
||||
rows = await statementRowsAsync.call(this.stmt, bindParameters[0]);
|
||||
} else {
|
||||
rows = await statementRowsAsync.call(this.stmt, bindParameters.flat());
|
||||
}
|
||||
const iter = {
|
||||
nextRows: Array(100),
|
||||
nextRowIndex: 100,
|
||||
next() {
|
||||
try {
|
||||
if (this.nextRowIndex === 100) {
|
||||
this.nextRows.fill(null);
|
||||
rowsNext.call(rows, this.nextRows);
|
||||
this.nextRowIndex = 0;
|
||||
}
|
||||
const row = this.nextRows[this.nextRowIndex];
|
||||
this.nextRows[this.nextRowIndex] = null;
|
||||
if (!row) {
|
||||
return { done: true };
|
||||
}
|
||||
this.nextRowIndex++;
|
||||
return { value: row, done: false };
|
||||
} catch (e) {
|
||||
throw convertError(e);
|
||||
}
|
||||
},
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
},
|
||||
};
|
||||
return iter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an array of the resulting rows.
|
||||
*
|
||||
* @param bindParameters - The bind parameters for executing the statement.
|
||||
*/
|
||||
async all(...bindParameters) {
|
||||
try {
|
||||
const result = [];
|
||||
const it = await this.iterate(...bindParameters);
|
||||
for (const row of it) {
|
||||
if (this.pluckMode) {
|
||||
result.push(row[Object.keys(row)[0]]);
|
||||
} else {
|
||||
result.push(row);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw convertError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts the statement.
|
||||
*/
|
||||
interrupt() {
|
||||
statementInterrupt.call(this.stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the columns in the result set returned by this prepared statement.
|
||||
*/
|
||||
columns() {
|
||||
return statementColumns.call(this.stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle 64-bit integer support.
|
||||
*/
|
||||
safeIntegers(toggle) {
|
||||
statementSafeIntegers.call(this.stmt, toggle ?? true);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Database;
|
||||
module.exports.Authorization = Authorization;
|
||||
module.exports.SqliteError = SqliteError;
|
||||
21
node_modules/libsql/sqlite-error.js
generated
vendored
Normal file
21
node_modules/libsql/sqlite-error.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
const descriptor = { value: 'SqliteError', writable: true, enumerable: false, configurable: true };
|
||||
|
||||
function SqliteError(message, code, rawCode) {
|
||||
if (new.target !== SqliteError) {
|
||||
return new SqliteError(message, code);
|
||||
}
|
||||
if (typeof code !== 'string') {
|
||||
throw new TypeError('Expected second argument to be a string');
|
||||
}
|
||||
Error.call(this, message);
|
||||
descriptor.value = '' + message;
|
||||
Object.defineProperty(this, 'message', descriptor);
|
||||
Error.captureStackTrace(this, SqliteError);
|
||||
this.code = code;
|
||||
this.rawCode = rawCode
|
||||
}
|
||||
Object.setPrototypeOf(SqliteError, Error);
|
||||
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
||||
Object.defineProperty(SqliteError.prototype, 'name', descriptor);
|
||||
module.exports = SqliteError;
|
||||
162
node_modules/libsql/types/index.d.ts
generated
vendored
Normal file
162
node_modules/libsql/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
// Type definitions for better-sqlite3 7.6
|
||||
// Project: https://github.com/JoshuaWise/better-sqlite3
|
||||
// Definitions by: Ben Davies <https://github.com/Morfent>
|
||||
// Mathew Rumsey <https://github.com/matrumz>
|
||||
// Santiago Aguilar <https://github.com/sant123>
|
||||
// Alessandro Vergani <https://github.com/loghorn>
|
||||
// Andrew Kaiser <https://github.com/andykais>
|
||||
// Mark Stewart <https://github.com/mrkstwrt>
|
||||
// Florian Stamer <https://github.com/stamerf>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.8
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
// FIXME: Is this `any` really necessary?
|
||||
type VariableArgFunction = (...params: any[]) => unknown;
|
||||
type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A) => unknown ? A : never;
|
||||
type ElementOf<T> = T extends Array<infer E> ? E : T;
|
||||
|
||||
declare namespace Libsql {
|
||||
interface Statement<BindParameters extends unknown[]> {
|
||||
database: Database;
|
||||
source: string;
|
||||
reader: boolean;
|
||||
readonly: boolean;
|
||||
busy: boolean;
|
||||
|
||||
run(...params: BindParameters): Database.RunResult;
|
||||
get(...params: BindParameters): unknown;
|
||||
all(...params: BindParameters): unknown[];
|
||||
iterate(...params: BindParameters): IterableIterator<unknown>;
|
||||
pluck(toggleState?: boolean): this;
|
||||
expand(toggleState?: boolean): this;
|
||||
raw(toggleState?: boolean): this;
|
||||
bind(...params: BindParameters): this;
|
||||
columns(): ColumnDefinition[];
|
||||
safeIntegers(toggleState?: boolean): this;
|
||||
}
|
||||
|
||||
interface ColumnDefinition {
|
||||
name: string;
|
||||
column: string | null;
|
||||
table: string | null;
|
||||
database: string | null;
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
interface Transaction<F extends VariableArgFunction> {
|
||||
(...params: ArgumentTypes<F>): ReturnType<F>;
|
||||
default(...params: ArgumentTypes<F>): ReturnType<F>;
|
||||
deferred(...params: ArgumentTypes<F>): ReturnType<F>;
|
||||
immediate(...params: ArgumentTypes<F>): ReturnType<F>;
|
||||
exclusive(...params: ArgumentTypes<F>): ReturnType<F>;
|
||||
}
|
||||
|
||||
interface VirtualTableOptions {
|
||||
rows: () => Generator;
|
||||
columns: string[];
|
||||
parameters?: string[] | undefined;
|
||||
safeIntegers?: boolean | undefined;
|
||||
directOnly?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface Database {
|
||||
memory: boolean;
|
||||
readonly: boolean;
|
||||
name: string;
|
||||
open: boolean;
|
||||
inTransaction: boolean;
|
||||
|
||||
prepare<BindParameters extends unknown[] | {} = unknown[]>(
|
||||
source: string,
|
||||
): BindParameters extends unknown[] ? Statement<BindParameters> : Statement<[BindParameters]>;
|
||||
transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
|
||||
sync(): any;
|
||||
exec(source: string): this;
|
||||
pragma(source: string, options?: Database.PragmaOptions): unknown;
|
||||
function(name: string, cb: (...params: unknown[]) => unknown): this;
|
||||
function(name: string, options: Database.RegistrationOptions, cb: (...params: unknown[]) => unknown): this;
|
||||
aggregate<T>(name: string, options: Database.RegistrationOptions & {
|
||||
start?: T | (() => T);
|
||||
step: (total: T, next: ElementOf<T>) => T | void;
|
||||
inverse?: ((total: T, dropped: T) => T) | undefined;
|
||||
result?: ((total: T) => unknown) | undefined;
|
||||
}): this;
|
||||
loadExtension(path: string): this;
|
||||
close(): this;
|
||||
defaultSafeIntegers(toggleState?: boolean): this;
|
||||
backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
|
||||
table(name: string, options: VirtualTableOptions): this;
|
||||
unsafeMode(unsafe?: boolean): this;
|
||||
serialize(options?: Database.SerializeOptions): Buffer;
|
||||
}
|
||||
|
||||
interface DatabaseConstructor {
|
||||
new (filename: string | Buffer, options?: Database.Options): Database;
|
||||
(filename: string, options?: Database.Options): Database;
|
||||
prototype: Database;
|
||||
|
||||
SqliteError: typeof SqliteError;
|
||||
}
|
||||
}
|
||||
|
||||
declare class SqliteError extends Error {
|
||||
name: string;
|
||||
message: string;
|
||||
code: string;
|
||||
rawCode?: number;
|
||||
constructor(message: string, code: string, rawCode?: number);
|
||||
}
|
||||
|
||||
declare namespace Database {
|
||||
interface RunResult {
|
||||
changes: number;
|
||||
lastInsertRowid: number | bigint;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
readonly?: boolean | undefined;
|
||||
fileMustExist?: boolean | undefined;
|
||||
timeout?: number | undefined;
|
||||
verbose?: ((message?: unknown, ...additionalArgs: unknown[]) => void) | undefined;
|
||||
nativeBinding?: string | undefined;
|
||||
syncUrl?: string | undefined;
|
||||
}
|
||||
|
||||
interface SerializeOptions {
|
||||
attached?: string;
|
||||
}
|
||||
|
||||
interface PragmaOptions {
|
||||
simple?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface RegistrationOptions {
|
||||
varargs?: boolean | undefined;
|
||||
deterministic?: boolean | undefined;
|
||||
safeIntegers?: boolean | undefined;
|
||||
directOnly?: boolean | undefined;
|
||||
}
|
||||
|
||||
type AggregateOptions = Parameters<Libsql.Database["aggregate"]>[1];
|
||||
|
||||
interface BackupMetadata {
|
||||
totalPages: number;
|
||||
remainingPages: number;
|
||||
}
|
||||
interface BackupOptions {
|
||||
progress: (info: BackupMetadata) => number;
|
||||
}
|
||||
|
||||
type SqliteError = typeof SqliteError;
|
||||
type Statement<BindParameters extends unknown[] | {} = unknown[]> = BindParameters extends unknown[]
|
||||
? Libsql.Statement<BindParameters>
|
||||
: Libsql.Statement<[BindParameters]>;
|
||||
type ColumnDefinition = Libsql.ColumnDefinition;
|
||||
type Transaction<T extends VariableArgFunction = VariableArgFunction> = Libsql.Transaction<T>;
|
||||
type Database = Libsql.Database;
|
||||
}
|
||||
|
||||
declare const Database: Libsql.DatabaseConstructor;
|
||||
export = Database;
|
||||
66
node_modules/libsql/types/promise.d.ts
generated
vendored
Normal file
66
node_modules/libsql/types/promise.d.ts
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
export = Database;
|
||||
/**
|
||||
* Database represents a connection that can prepare and execute SQL statements.
|
||||
*/
|
||||
declare class Database {
|
||||
/**
|
||||
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} path - Path to the database file.
|
||||
*/
|
||||
constructor(path: string, opts: any);
|
||||
db: any;
|
||||
memory: boolean;
|
||||
readonly: boolean;
|
||||
name: string;
|
||||
open: boolean;
|
||||
sync(): any;
|
||||
syncUntil(replicationIndex: any): any;
|
||||
/**
|
||||
* Prepares a SQL statement for execution.
|
||||
*
|
||||
* @param {string} sql - The SQL statement string to prepare.
|
||||
*/
|
||||
prepare(sql: string): any;
|
||||
/**
|
||||
* Returns a function that executes the given function in a transaction.
|
||||
*
|
||||
* @param {function} fn - The function to wrap in a transaction.
|
||||
*/
|
||||
transaction(fn: Function): (...bindParameters: any[]) => Promise<any>;
|
||||
pragma(source: any, options: any): any;
|
||||
backup(filename: any, options: any): void;
|
||||
serialize(options: any): void;
|
||||
function(name: any, options: any, fn: any): void;
|
||||
aggregate(name: any, options: any): void;
|
||||
table(name: any, factory: any): void;
|
||||
authorizer(rules: any): void;
|
||||
loadExtension(...args: any[]): void;
|
||||
maxWriteReplicationIndex(): any;
|
||||
/**
|
||||
* Executes a SQL statement.
|
||||
*
|
||||
* @param {string} sql - The SQL statement string to execute.
|
||||
*/
|
||||
exec(sql: string): any;
|
||||
/**
|
||||
* Interrupts the database connection.
|
||||
*/
|
||||
interrupt(): void;
|
||||
/**
|
||||
* Closes the database connection.
|
||||
*/
|
||||
close(): void;
|
||||
/**
|
||||
* Toggle 64-bit integer support.
|
||||
*/
|
||||
defaultSafeIntegers(toggle: any): this;
|
||||
unsafeMode(...args: any[]): void;
|
||||
}
|
||||
declare namespace Database {
|
||||
export { Authorization, SqliteError };
|
||||
}
|
||||
import Authorization = require("./auth");
|
||||
import SqliteError = require("./sqlite-error");
|
||||
//# sourceMappingURL=promise.d.ts.map
|
||||
Reference in New Issue
Block a user