xeondb-driver 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/readme.md +107 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xeondb-driver",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Node.js client for Xeondb.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -24,5 +24,6 @@
24
24
  },
25
25
  "homepage": "https://github.com/Voyrox/Xeondb#readme",
26
26
  "author": "Voyrox",
27
- "license": "MIT"
28
- }
27
+ "license": "MIT",
28
+ "readme": "readme.md"
29
+ }
package/readme.md ADDED
@@ -0,0 +1,107 @@
1
+ # XeonDB NodeJS driver
2
+ This package provides a NodeJS driver for XeonDB, allowing you to connect to a XeonDB instance and execute SQL queries from your NodeJS applications.
3
+
4
+ ## Highlights
5
+ - **Lightweight and efficient**: Minimal dependencies and optimized for performance.
6
+ - **Full SQL support**: Execute a wide range of SQL commands supported by XeonDB.
7
+ - **Easy connection management**: Simple API for connecting, disconnecting, and handling connection errors.
8
+ - **Asynchronous operations**: All database interactions are asynchronous, leveraging Promises for better performance and scalability.
9
+ - **Comprehensive error handling**: Detailed error messages to help you debug issues quickly
10
+
11
+ ## Commands supported
12
+ Please refer to the [documentation](https://voyrox.github.io/Xeondb/) for a complete list of supported SQL commands and their syntax. The NodeJS driver supports executing any SQL command that XeonDB recognizes.
13
+
14
+ ## queryTable vs query
15
+
16
+ - QueryTable: This method is specifically designed for executing SQL statements that interact with tables. It is optimized for handling operations such as creating tables, inserting data, selecting records, updating existing entries, and deleting records. The `queryTable` method typically returns results in a structured format that is easy to work with when dealing with tabular data.
17
+ - Example usage of `queryTable`:
18
+ ```javascript
19
+ const result = await client.queryTable('SELECT * FROM my_table;');
20
+ console.log(result);
21
+ ```
22
+
23
+ - Query: This method is a more general-purpose function that can be used for executing any SQL statement, including those that may not directly interact with tables (e.g., administrative commands, configuration changes). The `query` method may return results in a less structured format, depending on the nature of the command being executed.
24
+ - Example usage of `query`:
25
+ ```javascript
26
+ const result = await client.query('PING;');
27
+ console.log(result);
28
+ ```
29
+
30
+
31
+ ## Example usage
32
+ ```javascript
33
+ const { XeondbClient } = require('./nodeJS');
34
+
35
+ async function main() {
36
+ const host = process.env.Xeondb_HOST || '127.0.0.1';
37
+ const port = Number(process.env.Xeondb_PORT || 9876);
38
+ const client = new XeondbClient({ host, port });
39
+
40
+ const keyspace = 'testKeyspace';
41
+ const table = 'testTable';
42
+
43
+ try {
44
+ console.log(`Connecting to Xeondb at ${host}:${port}...`);
45
+ const connected = await client.connect();
46
+ if (!connected) {
47
+ throw new Error('Unable to establish a connection to the database.');
48
+ }
49
+ console.log('Successfully connected to the database.');
50
+
51
+ await client.queryTable(`CREATE KEYSPACE IF NOT EXISTS ${keyspace};`);
52
+ await client.selectKeyspace(keyspace);
53
+ console.log(`Using keyspace: ${keyspace}`);
54
+
55
+ await client.queryTable(
56
+ `CREATE TABLE IF NOT EXISTS ${table} (id int64, value varchar, PRIMARY KEY (id));`
57
+ );
58
+ console.log(`Table '${table}' is ready.`);
59
+
60
+ await client.queryTable(
61
+ `INSERT INTO ${table} (id, value) VALUES (1, "hello"), (2, "world");`
62
+ );
63
+ console.log('Inserted initial records.');
64
+
65
+ await client.queryTable(`UPDATE ${table} SET value = "HELLO" WHERE id = 1;`);
66
+ let result = await client.queryTable(`SELECT * FROM ${table} WHERE id = 1;`);
67
+ console.log('After update (id=1):', result);
68
+
69
+ await client.queryTable(`UPDATE ${table} SET value = "new" WHERE id = 3;`);
70
+ result = await client.queryTable(`SELECT * FROM ${table} WHERE id = 3;`);
71
+ console.log('After update (id=3):', result);
72
+
73
+ result = await client.queryTable(`SELECT * FROM ${table} WHERE id = 1;`);
74
+ console.log('Current (id=1):', result);
75
+
76
+ await client.queryTable(`DELETE FROM ${table} WHERE id = 1;`);
77
+ result = await client.queryTable(`SELECT * FROM ${table} WHERE id = 1;`);
78
+ console.log('After delete (id=1):', result);
79
+
80
+ result = await client.queryTable(`SELECT * FROM ${table} WHERE id = 2;`);
81
+ console.log('Current (id=2):', result);
82
+
83
+ console.log('All operations completed successfully.');
84
+ } catch (error) {
85
+ console.error('An error occurred during the test execution:', error);
86
+ process.exitCode = 1;
87
+ } finally {
88
+ client.close();
89
+ console.log('Database connection closed.');
90
+ }
91
+ }
92
+
93
+ main();
94
+ ```
95
+
96
+
97
+ ## Devnotes
98
+
99
+ ### Run before publishing
100
+ ```bash
101
+ npm version patch
102
+ ```
103
+
104
+ ### Publish changes to npm
105
+ ```bash
106
+ npm publish --access public
107
+ ```