@tursodatabase/serverless 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,22 @@
1
- # Turso serverless JavaScript driver
1
+ <p align="center">
2
+ <h1 align="center">Turso Serverless Driver for JavaScript</h1>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a title="JavaScript" target="_blank" href="https://www.npmjs.com/package/@tursodatabase/serverless"><img alt="npm" src="https://img.shields.io/npm/v/@tursodatabase/serverless"></a>
7
+ <a title="MIT" target="_blank" href="https://github.com/tursodatabase/turso/blob/main/LICENSE.md"><img src="http://img.shields.io/badge/license-MIT-orange.svg?style=flat-square"></a>
8
+ </p>
9
+ <p align="center">
10
+ <a title="Users Discord" target="_blank" href="https://tur.so/discord"><img alt="Chat with other users of Turso on Discord" src="https://img.shields.io/discord/933071162680958986?label=Discord&logo=Discord&style=social"></a>
11
+ </p>
12
+
13
+ ---
14
+
15
+ ## About
2
16
 
3
17
  A serverless database driver for Turso Cloud, using only `fetch()`. Connect to your database from serverless and edge functions, such as Cloudflare Workers and Vercel.
4
18
 
5
- > [!NOTE]
6
- > This driver is experimental and, therefore, subject to change at any time.
19
+ > **📝 Note:** This driver is experimental and, therefore, subject to change at any time.
7
20
 
8
21
  ## Installation
9
22
 
@@ -11,7 +24,9 @@ A serverless database driver for Turso Cloud, using only `fetch()`. Connect to y
11
24
  npm install @tursodatabase/serverless
12
25
  ```
13
26
 
14
- ## Usage
27
+ ## Getting Started
28
+
29
+ ### Basic Usage
15
30
 
16
31
  ```javascript
17
32
  import { connect } from "@tursodatabase/serverless";
@@ -36,7 +51,11 @@ console.log(rows);
36
51
  for await (const row of stmt.iterate([123])) {
37
52
  console.log(row);
38
53
  }
54
+ ```
55
+
56
+ ### Batch Operations
39
57
 
58
+ ```javascript
40
59
  // Execute multiple statements in a batch
41
60
  await conn.batch([
42
61
  "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, email TEXT)",
@@ -45,9 +64,9 @@ await conn.batch([
45
64
  ]);
46
65
  ```
47
66
 
48
- ### Compatibility layer for libSQL API
67
+ ### libSQL Compatibility Layer
49
68
 
50
- This driver supports the libSQL API as a compatibility layer.
69
+ For existing libSQL applications, use the compatibility layer:
51
70
 
52
71
  ```javascript
53
72
  import { createClient } from "@tursodatabase/serverless/compat";
@@ -73,6 +92,21 @@ await client.batch([
73
92
 
74
93
  Check out the `examples/` directory for complete usage examples.
75
94
 
95
+ ## API Reference
96
+
97
+ For complete API documentation, see [JavaScript API Reference](../../docs/javascript-api-reference.md).
98
+
99
+ ## Related Packages
100
+
101
+ * The [@tursodatabase/database](https://www.npmjs.com/package/@tursodatabase/database) package provides the Turso in-memory database, compatible with SQLite.
102
+ * The [@tursodatabase/sync](https://www.npmjs.com/package/@tursodatabase/sync) package provides bidirectional sync between a local Turso database and Turso Cloud.
103
+
76
104
  ## License
77
105
 
78
- MIT
106
+ This project is licensed under the [MIT license](../../LICENSE.md).
107
+
108
+ ## Support
109
+
110
+ - [GitHub Issues](https://github.com/tursodatabase/turso/issues)
111
+ - [Documentation](https://docs.turso.tech)
112
+ - [Discord Community](https://tur.so/discord)
@@ -14,6 +14,7 @@ export interface Config extends SessionConfig {
14
14
  export declare class Connection {
15
15
  private config;
16
16
  private session;
17
+ private isOpen;
17
18
  constructor(config: Config);
18
19
  /**
19
20
  * Prepare a SQL statement for execution.
@@ -8,6 +8,7 @@ import { Statement } from './statement.js';
8
8
  */
9
9
  export class Connection {
10
10
  constructor(config) {
11
+ this.isOpen = true;
11
12
  if (!config.url) {
12
13
  throw new Error("invalid config: url is required");
13
14
  }
@@ -30,6 +31,9 @@ export class Connection {
30
31
  * ```
31
32
  */
32
33
  prepare(sql) {
34
+ if (!this.isOpen) {
35
+ throw new TypeError("The database connection is not open");
36
+ }
33
37
  return new Statement(this.config, sql);
34
38
  }
35
39
  /**
@@ -45,6 +49,9 @@ export class Connection {
45
49
  * ```
46
50
  */
47
51
  async exec(sql) {
52
+ if (!this.isOpen) {
53
+ throw new TypeError("The database connection is not open");
54
+ }
48
55
  return this.session.sequence(sql);
49
56
  }
50
57
  /**
@@ -73,6 +80,9 @@ export class Connection {
73
80
  * @returns Promise resolving to the result of the pragma
74
81
  */
75
82
  async pragma(pragma) {
83
+ if (!this.isOpen) {
84
+ throw new TypeError("The database connection is not open");
85
+ }
76
86
  const sql = `PRAGMA ${pragma}`;
77
87
  return this.session.execute(sql);
78
88
  }
@@ -82,6 +92,7 @@ export class Connection {
82
92
  * This sends a close request to the server to properly clean up the stream.
83
93
  */
84
94
  async close() {
95
+ this.isOpen = false;
85
96
  await this.session.close();
86
97
  }
87
98
  }
package/dist/statement.js CHANGED
@@ -97,11 +97,15 @@ export class Statement {
97
97
  const normalizedArgs = this.normalizeArgs(args);
98
98
  const result = await this.session.execute(this.sql, normalizedArgs);
99
99
  if (this.presentationMode === 'raw') {
100
- // In raw mode, return arrays of values
101
- // Each row is already an array with column properties added
102
100
  return result.rows.map((row) => [...row]);
103
101
  }
104
- return result.rows;
102
+ return result.rows.map((row) => {
103
+ const obj = {};
104
+ result.columns.forEach((col, i) => {
105
+ obj[col] = row[i];
106
+ });
107
+ return obj;
108
+ });
105
109
  }
106
110
  /**
107
111
  * Execute the statement and return an async iterator for streaming results.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tursodatabase/serverless",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",