Skip to content

Commit ed5cd24

Browse files
authored
Refactor client library (#4)
* Add query impls * Add config module * Refactor entire client library We make several changes including: - A separate `Connection` object - A special `Empty` class for empty response (to differentiate from null values) - Only allow query objects to be sent - Use a buffer list for all parameters * Fix query packet generation and update README
1 parent 86088c5 commit ed5cd24

File tree

16 files changed

+451
-542
lines changed

16 files changed

+451
-542
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.devcontainer
33
dist
4-
.vscode
4+
.vscode
5+
.rollup_cache

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
# Skytable NodeJS Driver
1+
# `skytable-node`: Skytable driver for NodeJS
22

3-
This is the skeleton template repository for Skytable's NodeJS driver. You can [track the implementation here](https://github.com/skytable/skytable/issues/324)!
3+
## Getting started
44

5-
Tasks:
6-
- [ ] Implement a basic Skytable client driver for NodeJS
7-
- [ ] Functionality:
8-
- [ ] Implement the full Skyhash protocol
9-
- [ ] Be able to send and receive queries and decode them ergonomically (into appropriate objects and/or types)
10-
- [ ] Should have a way to use TLS
5+
```shell
6+
yarn add skytable-node
7+
```
118

12-
> For contributors: You might find the [Rust client driver](https://github.com/skytable/client-rust) to be a good reference.
13-
> We're here to help! Please jump into our [Discord Community](https://discord.gg/QptWFdx); we're here to mentor you.
9+
## Example
10+
11+
```js
12+
const { Config, Query } = require('skytable-node');
13+
const cfg = new Config("root", "password");
14+
15+
async function main() {
16+
let db;
17+
try {
18+
db = await cfg.connect();
19+
console.log(await db.query(new Query("sysctl report status")));
20+
} catch (e) {
21+
console.error(e);
22+
process.exit(1);
23+
} finally {
24+
if (db) {
25+
await db.disconnect();
26+
}
27+
}
28+
}
29+
30+
main()
31+
```
1432

1533
## License
1634

__tests__/dcl.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Config, Query } from '../src';
2+
3+
const cfg = new Config('root', 'password');
4+
5+
async function main() {
6+
let db;
7+
try {
8+
db = await cfg.connect();
9+
console.log(await db.query(new Query('sysctl report status')));
10+
} catch (e) {
11+
console.error(e);
12+
process.exit(1);
13+
} finally {
14+
if (db) {
15+
await db.disconnect();
16+
}
17+
}
18+
}
19+
20+
main();

__tests__/ddl.spec.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

__tests__/dml.spec.ts

Lines changed: 0 additions & 122 deletions
This file was deleted.

__tests__/utils.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

examples/simple.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { Config, Query } = require('skytable-node');
2+
const cfg = new Config('root', 'password');
3+
4+
async function main() {
5+
let db;
6+
try {
7+
db = await cfg.connect();
8+
console.log(await db.query(new Query('sysctl report status')));
9+
} catch (e) {
10+
console.error(e);
11+
process.exit(1);
12+
} finally {
13+
if (db) {
14+
await db.disconnect();
15+
}
16+
}
17+
}
18+
19+
main();

examples/simple.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skytable-node",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"main": "dist/cjs/index.js",
55
"types": "dist/cjs/index.d.ts",
66
"module": "dist/esm/index.mjs",

0 commit comments

Comments
 (0)