Skip to content

Commit 01887b0

Browse files
committed
Initial push from Efrem Ropelato
1 parent 406729d commit 01887b0

File tree

14 files changed

+1706
-133
lines changed

14 files changed

+1706
-133
lines changed

.gitignore

Lines changed: 1 addition & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,2 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
.pnpm-debug.log*
9-
10-
# Diagnostic reports (https://nodejs.org/api/report.html)
11-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12-
13-
# Runtime data
14-
pids
15-
*.pid
16-
*.seed
17-
*.pid.lock
18-
19-
# Directory for instrumented libs generated by jscoverage/JSCover
20-
lib-cov
21-
22-
# Coverage directory used by tools like istanbul
23-
coverage
24-
*.lcov
25-
26-
# nyc test coverage
27-
.nyc_output
28-
29-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30-
.grunt
31-
32-
# Bower dependency directory (https://bower.io/)
33-
bower_components
34-
35-
# node-waf configuration
36-
.lock-wscript
37-
38-
# Compiled binary addons (https://nodejs.org/api/addons.html)
39-
build/Release
40-
41-
# Dependency directories
1+
build/
422
node_modules/
43-
jspm_packages/
44-
45-
# Snowpack dependency directory (https://snowpack.dev/)
46-
web_modules/
47-
48-
# TypeScript cache
49-
*.tsbuildinfo
50-
51-
# Optional npm cache directory
52-
.npm
53-
54-
# Optional eslint cache
55-
.eslintcache
56-
57-
# Optional stylelint cache
58-
.stylelintcache
59-
60-
# Microbundle cache
61-
.rpt2_cache/
62-
.rts2_cache_cjs/
63-
.rts2_cache_es/
64-
.rts2_cache_umd/
65-
66-
# Optional REPL history
67-
.node_repl_history
68-
69-
# Output of 'npm pack'
70-
*.tgz
71-
72-
# Yarn Integrity file
73-
.yarn-integrity
74-
75-
# dotenv environment variable files
76-
.env
77-
.env.development.local
78-
.env.test.local
79-
.env.production.local
80-
.env.local
81-
82-
# parcel-bundler cache (https://parceljs.org/)
83-
.cache
84-
.parcel-cache
85-
86-
# Next.js build output
87-
.next
88-
out
89-
90-
# Nuxt.js build / generate output
91-
.nuxt
92-
dist
93-
94-
# Gatsby files
95-
.cache/
96-
# Comment in the public line in if your project uses Gatsby and not Next.js
97-
# https://nextjs.org/blog/next-9-1#public-directory-support
98-
# public
99-
100-
# vuepress build output
101-
.vuepress/dist
102-
103-
# vuepress v2.x temp and cache directory
104-
.temp
105-
.cache
106-
107-
# Docusaurus cache and generated files
108-
.docusaurus
109-
110-
# Serverless directories
111-
.serverless/
112-
113-
# FuseBox cache
114-
.fusebox/
115-
116-
# DynamoDB Local files
117-
.dynamodb/
118-
119-
# TernJS port file
120-
.tern-port
121-
122-
# Stores VSCode versions used for testing VSCode extensions
123-
.vscode-test
124-
125-
# yarn v2
126-
.yarn/cache
127-
.yarn/unplugged
128-
.yarn/build-state.yml
129-
.yarn/install-state.gz
130-
.pnp.*

.vscode/c_cpp_properties.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"${workspaceFolder}/node_modules/node-addon-api"
8+
],
9+
"defines": [],
10+
"macFrameworkPath": [
11+
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
12+
],
13+
"compilerPath": "/usr/bin/clang",
14+
"cStandard": "c17",
15+
"cppStandard": "c++17",
16+
"intelliSenseMode": "macos-clang-arm64"
17+
}
18+
],
19+
"version": 4
20+
}

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"vadimcn.vscode-lldb"
4+
]
5+
}

.vscode/launch.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
// Usare IntelliSense per informazioni sui possibili attributi.
3+
// Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti.
4+
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch via NPM",
9+
"request": "launch",
10+
"runtimeArgs": [
11+
"start"
12+
],
13+
"runtimeExecutable": "npm",
14+
"skipFiles": [
15+
"<node_internals>/**"
16+
],
17+
"type": "node"
18+
},
19+
{
20+
"type": "lldb",
21+
"request": "launch",
22+
"name": "Launch Program",
23+
"preLaunchTask": "npm: build:dev",
24+
"program": "node",
25+
"args": [
26+
"${workspaceFolder}/example/index.js"
27+
]
28+
}]
29+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"*.ifc": "ifc",
4+
"*.json": "json",
5+
"string": "cpp"
6+
}
7+
}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "build:dev",
7+
"group": "build",
8+
"problemMatcher": [],
9+
"label": "npm: build:dev",
10+
"detail": "node-gyp -j 16 build --debug"
11+
}
12+
]
13+
}

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 CrossDB
3+
Copyright (c) 2024 Efrem Ropelato
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
# crossdb-nodejs
2-
CrossDB Node.js connector
1+
# NodeJS Driver for CrossDB
2+
3+
## Pre-requirement
4+
You need to [install](https://crossdb.org/get-started/install/) crossdb lib first
5+
6+
> not ready for production
7+
8+
## Run Example
9+
10+
```sh
11+
npm install
12+
npm start
13+
```

binding.gyp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "crossdb",
5+
"sources": [ "src/crossdb_binding.cc" ],
6+
"libraries": [
7+
"-L/usr/local/lib",
8+
"-lcrossdb"
9+
],
10+
"cflags": ["-std=c++17"],
11+
"cflags!": [ "-fno-exceptions" ],
12+
"cflags_cc!": [ "-fno-exceptions" ],
13+
"include_dirs": ["<!@(node -p \"require('node-addon-api').include\")"],
14+
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
15+
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"]
16+
}
17+
]
18+
}

example/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
const CrossDB = require('../index');
3+
4+
const db = new CrossDB(':memory:');
5+
6+
try {
7+
// Create Table
8+
db.exec("CREATE TABLE IF NOT EXISTS student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info VARCHAR(255))");
9+
db.exec("CREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(255), INDEX (name))");
10+
db.exec("CREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name))");
11+
console.log("Tables 'student','teacher' and 'book' created.");
12+
// clean table
13+
db.exec("DELETE FROM student");
14+
db.exec("DELETE FROM teacher");
15+
db.exec("DELETE FROM book");
16+
17+
db.begin();
18+
console.log("Begin transaction");
19+
20+
// Insert
21+
db.exec("INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)");
22+
db.exec("INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')", "He is a boy.\nHe likes playing football.\nWe all like him!");
23+
db.exec("INSERT INTO student (id,name,age,class,score,info) VALUES (7,'Wendy',10,'3-1',95,'%s')", "She is a girl.\nShe likes cooking.\nWe all love her!");
24+
db.exec("INSERT INTO teacher (id,name,age) VALUES (1,'Tomas',40),(2,'Steven',50),(3,'Bill',31),(4,'Lucy',29)");
25+
db.exec("INSERT INTO book (id,name,author,count) VALUES (1,'Romeo and Juliet','Shakespeare',10),(2,'Pride and Prejudice','Austen',5),(3,'Great Expectations','Dickens',8),(4,'Sorrows of Young Werther','Von Goethe',4)");
26+
console.log("Data inserted.");
27+
28+
// Select
29+
let res = db.exec("SELECT * FROM student");
30+
console.log("Select all student: ", res);
31+
32+
// Update
33+
db.exec("UPDATE student set age=9 WHERE id = 2");
34+
console.log("Update age = 9 for student with id = 2");
35+
36+
res = db.exec("SELECT id,name,age,class,score from student WHERE id = 2");
37+
console.log("Select student with id = 2: ", res);
38+
39+
db.exec("DELETE FROM student WHERE id = 3");
40+
console.log("User with ID 3 deleted.");
41+
42+
res = db.exec("SELECT * from student WHERE id = 3");
43+
console.log("Select student with id = 3: ", res);
44+
45+
// Aggregation function
46+
res = db.exec("SELECT COUNT(*),MIN(score),MAX(score),SUM(score),AVG(score) FROM student");
47+
console.log("Select student's AGG COUNT,MIN,MAX,SUM,AVG: ", res);
48+
49+
db.commit();
50+
console.log("Commit transaction");
51+
52+
db.begin();
53+
console.log("Begin transaction");
54+
// Update
55+
db.exec("UPDATE student set age=15 WHERE id = 2");
56+
console.log("Update age = 15 for student with id = 2");
57+
// Select
58+
res = db.exec("SELECT id,name,age,class,score from student WHERE id = 2");
59+
console.log("Select student with id = 2: ", res);
60+
db.rollback();
61+
console.log("Rollback transaction");
62+
res = db.exec("SELECT id,name,age,class,score from student WHERE id = 2");
63+
console.log("Select student with id = 2: ", res);
64+
65+
// Multi-Statements
66+
res = db.exec("SELECT COUNT(*) as Count FROM student; SELECT id,name FROM student WHERE id=2");
67+
console.log("Multi Select student: ", res);
68+
69+
} catch (err) {
70+
console.error("Error during operation:", err);
71+
db.rollback();
72+
console.log("Rollback transaction");
73+
} finally {
74+
console.log("\nCrossDB Simulation Complete.");
75+
db.close();
76+
console.log("Database connection closed.");
77+
}

0 commit comments

Comments
 (0)