libsql-stateless-easy
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -56,8 +56,13 @@ "use strict"; | ||
} | ||
return { | ||
const resultset = { | ||
rows: Rows, | ||
columns: res.cols.map(c => c.name), | ||
columns: res.cols.map(c => c.name || ""), | ||
columnTypes: res.cols.map(c => c.decltype || ""), | ||
rowsAffected: res.affected_row_count, | ||
lastInsertRowid: (res.last_insert_rowid) ? BigInt(res.last_insert_rowid) : undefined | ||
lastInsertRowid: (res.last_insert_rowid) ? BigInt(res.last_insert_rowid) : undefined, | ||
}; | ||
return { | ||
...resultset, | ||
toJSON: () => { return resultset; } | ||
}; | ||
} | ||
@@ -64,0 +69,0 @@ exports.libsqlStatementResParser = libsqlStatementResParser; |
@@ -52,8 +52,13 @@ import { Base64 } from "js-base64"; | ||
} | ||
return { | ||
const resultset = { | ||
rows: Rows, | ||
columns: res.cols.map(c => c.name), | ||
columns: res.cols.map(c => c.name || ""), | ||
columnTypes: res.cols.map(c => c.decltype || ""), | ||
rowsAffected: res.affected_row_count, | ||
lastInsertRowid: (res.last_insert_rowid) ? BigInt(res.last_insert_rowid) : undefined | ||
lastInsertRowid: (res.last_insert_rowid) ? BigInt(res.last_insert_rowid) : undefined, | ||
}; | ||
return { | ||
...resultset, | ||
toJSON: () => { return resultset; } | ||
}; | ||
} | ||
@@ -60,0 +65,0 @@ //======================================================== |
@@ -7,15 +7,76 @@ export type rawValue = null | bigint | number | string | Uint8Array; | ||
}; | ||
/** Row returned from the database. This is an Array-like object (it has `length` and can be indexed with a | ||
* number), and in addition, it has enumerable properties from the named columns. */ | ||
/** Row returned from an SQL statement. | ||
* | ||
* The row object can be used as an `Array` or as an object: | ||
* | ||
* ```javascript | ||
* const rs = await client.execute("SELECT name, title FROM books"); | ||
* for (const row in rs.rows) { | ||
* // Get the value from column `name` | ||
* console.log(row.name); | ||
* // Get the value from second column (`title`) | ||
* console.log(row[1]); | ||
* } | ||
* ``` | ||
*/ | ||
export interface Row { | ||
/** Number of columns in this row. | ||
* | ||
* All rows in one {@link ResultSet} have the same number and names of columns. | ||
*/ | ||
length: number; | ||
/** Columns can be accessed like an array by numeric indexes. */ | ||
[index: number]: rawValue; | ||
/** Columns can be accessed like an object by column names. */ | ||
[name: string]: rawValue; | ||
} | ||
export type ResultSet = { | ||
/** Result of executing an SQL statement. | ||
* | ||
* ```javascript | ||
* const rs = await client.execute("SELECT name, title FROM books"); | ||
* console.log(`Found ${rs.rows.length} books`); | ||
* for (const row in rs.rows) { | ||
* console.log(`Book ${row[0]} by ${row[1]}`); | ||
* } | ||
* | ||
* const rs = await client.execute("DELETE FROM books WHERE author = 'Jane Austen'"); | ||
* console.log(`Deleted ${rs.rowsAffected} books`); | ||
* ``` | ||
*/ | ||
export interface ResultSet { | ||
/** Names of columns. | ||
* | ||
* Names of columns can be defined using the `AS` keyword in SQL: | ||
* | ||
* ```sql | ||
* SELECT author AS author, COUNT(*) AS count FROM books GROUP BY author | ||
* ``` | ||
*/ | ||
columns: Array<string>; | ||
/** Types of columns. | ||
* | ||
* The types are currently shown for types declared in a SQL table. For | ||
* column types of function calls, for example, an empty string is | ||
* returned. | ||
*/ | ||
columnTypes: Array<string>; | ||
/** Rows produced by the statement. */ | ||
rows: Array<Row>; | ||
columns: Array<string>; | ||
/** Number of rows that were affected by an UPDATE, INSERT or DELETE operation. | ||
* | ||
* This value is not specified for other SQL statements. | ||
*/ | ||
rowsAffected: number; | ||
/** ROWID of the last inserted row. | ||
* | ||
* This value is not specified if the SQL statement was not an INSERT or if the table was not a ROWID | ||
* table. | ||
*/ | ||
lastInsertRowid: bigint | undefined; | ||
}; | ||
/** Converts the result set to JSON. | ||
* | ||
* This is used automatically by `JSON.stringify()`, but you can also call it explicitly. | ||
*/ | ||
toJSON(): any; | ||
} | ||
/** Transaction mode. | ||
@@ -22,0 +83,0 @@ * |
{ | ||
"name": "libsql-stateless-easy", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"homepage": "https://github.com/DaBigBlob/libsql-stateless-easy#readme", | ||
@@ -5,0 +5,0 @@ "repository": { |
58649
1298