kinetic-sql 1.0.2 → 1.0.4
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 +35 -19
- package/package.json +4 -2
- package/scripts/postinstall.js +44 -0
package/README.md
CHANGED
|
@@ -19,14 +19,14 @@ Kinetic SQL is a next-gen Node.js client that wraps **PostgreSQL** and **MySQL**
|
|
|
19
19
|
### 1. Install
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
|
|
23
|
-
# For PostgreSQL
|
|
24
|
-
|
|
22
|
+
# For PostgreSQL:
|
|
25
23
|
npm install kinetic-sql drizzle-orm postgres
|
|
26
24
|
|
|
27
|
-
# For MySQL
|
|
28
|
-
|
|
25
|
+
# For MySQL:
|
|
29
26
|
npm install kinetic-sql drizzle-orm mysql2 @rodrigogs/mysql-events
|
|
27
|
+
|
|
28
|
+
# For SQLite (Local Dev / Edge):
|
|
29
|
+
npm install kinetic-sql better-sqlite3
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
### 2. Initialize
|
|
@@ -34,12 +34,19 @@ npm install kinetic-sql drizzle-orm mysql2 @rodrigogs/mysql-events
|
|
|
34
34
|
```typescript
|
|
35
35
|
import { KineticClient } from 'kinetic-sql';
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
/* PostgreSQL/MySQL Example */
|
|
38
|
+
/* Connects using your DATABASE_URL env var by default */
|
|
38
39
|
const db = await KineticClient.create({
|
|
39
40
|
type: 'pg', // or 'mysql'
|
|
40
41
|
connectionString: process.env.DATABASE_URL,
|
|
41
42
|
realtimeEnabled: true
|
|
42
43
|
});
|
|
44
|
+
|
|
45
|
+
/* SQLite Example */
|
|
46
|
+
const db = await KineticClient.create({
|
|
47
|
+
type: 'sqlite',
|
|
48
|
+
filename: './dev.db'
|
|
49
|
+
});
|
|
43
50
|
```
|
|
44
51
|
|
|
45
52
|
### 3. Generate Types (The Magic)
|
|
@@ -47,14 +54,16 @@ realtimeEnabled: true
|
|
|
47
54
|
Run this command in your terminal. It reads your DB and patches the library automatically.
|
|
48
55
|
|
|
49
56
|
```bash
|
|
50
|
-
|
|
51
57
|
# PostgreSQL (Default)
|
|
52
|
-
|
|
53
58
|
npx k-sql gen --connection "postgres://..."
|
|
59
|
+
OR
|
|
60
|
+
npx k-sql gen --type pg --host localhost --user postgres --db mydb
|
|
54
61
|
|
|
55
62
|
# MySQL
|
|
56
|
-
|
|
57
63
|
npx k-sql gen --type mysql --host localhost --user root --db mydb
|
|
64
|
+
|
|
65
|
+
# SQLite
|
|
66
|
+
npx k-sql gen --type sqlite --db ./dev.db
|
|
58
67
|
```
|
|
59
68
|
|
|
60
69
|
---
|
|
@@ -66,7 +75,7 @@ npx k-sql gen --type mysql --host localhost --user root --db mydb
|
|
|
66
75
|
#### Listen to database events without setting up WebSockets.
|
|
67
76
|
|
|
68
77
|
```typescript
|
|
69
|
-
|
|
78
|
+
/* 'tasks' is auto-completed! */
|
|
70
79
|
const sub = await db.subscribe('tasks', (event) => {
|
|
71
80
|
console.log(event.action); // 'INSERT' | 'UPDATE'
|
|
72
81
|
console.log(event.data.title); // Typed!
|
|
@@ -81,11 +90,12 @@ await sub.unsubscribe();
|
|
|
81
90
|
#### Call stored procedures as native JS methods.
|
|
82
91
|
|
|
83
92
|
```typescript
|
|
84
|
-
|
|
85
|
-
const { data, error } = await db.rpc(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
93
|
+
/* 'add_todo' is auto-completed! */
|
|
94
|
+
const { data, error } = await db.rpc(
|
|
95
|
+
'add_todo',
|
|
96
|
+
/* Param names are checked! */
|
|
97
|
+
{ p_title: "Build cool app", p_user_id: 123 }
|
|
98
|
+
);
|
|
89
99
|
```
|
|
90
100
|
|
|
91
101
|
### Standard Queries (via Drizzle) ✨
|
|
@@ -106,7 +116,6 @@ const users = await db.orm
|
|
|
106
116
|
## ⚙️ Configuration
|
|
107
117
|
|
|
108
118
|
### PostgreSQL
|
|
109
|
-
|
|
110
119
|
```typescript
|
|
111
120
|
const db = await KineticClient.create({
|
|
112
121
|
type: 'pg',
|
|
@@ -120,7 +129,6 @@ realtimeEnabled: true
|
|
|
120
129
|
```
|
|
121
130
|
|
|
122
131
|
### MySQL
|
|
123
|
-
|
|
124
132
|
```typescript
|
|
125
133
|
const db = await KineticClient.create({
|
|
126
134
|
type: 'mysql',
|
|
@@ -133,12 +141,20 @@ realtimeEnabled: true // Requires Binary Logging enabled on server
|
|
|
133
141
|
});
|
|
134
142
|
```
|
|
135
143
|
|
|
144
|
+
### SQLite
|
|
145
|
+
```typescript
|
|
146
|
+
const db = await KineticClient.create({
|
|
147
|
+
type: 'sqlite',
|
|
148
|
+
filename: './prisma/dev.db' // Path to your file
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
136
152
|
## ⚠️ Requirements
|
|
137
153
|
|
|
138
154
|
- **Node.js:** 18+
|
|
139
155
|
- **PostgreSQL:** 12+ (Native `LISTEN/NOTIFY` used)
|
|
140
|
-
- **MySQL:** 5.7+
|
|
141
|
-
|
|
156
|
+
- **MySQL:** 5.7+ (Requires Binary Logging Enabled i.e. ` log_bin = ON ` for Realtime features)
|
|
157
|
+
- **SQLite:** 3+ (Bundled with `better-sqlite3`)
|
|
142
158
|
|
|
143
159
|
## 📄 License
|
|
144
160
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kinetic-sql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Zero-config, type-safe Postgres & MySQL client with Realtime subscriptions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"build": "tsup",
|
|
10
10
|
"prepublishOnly": "npm run build",
|
|
11
11
|
"dev": "tsup --watch",
|
|
12
|
-
"gen": "node dist/cli/generate.cjs"
|
|
12
|
+
"gen": "node dist/cli/generate.cjs",
|
|
13
|
+
"postinstall": "node scripts/postinstall.js"
|
|
13
14
|
},
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
25
26
|
"dist",
|
|
27
|
+
"scripts",
|
|
26
28
|
"README.md",
|
|
27
29
|
"LICENSE"
|
|
28
30
|
],
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ANSI Color Codes for the "Bling"
|
|
4
|
+
const RESET = "\x1b[0m";
|
|
5
|
+
const BRIGHT = "\x1b[1m";
|
|
6
|
+
const DIM = "\x1b[2m";
|
|
7
|
+
const CYAN = "\x1b[36m";
|
|
8
|
+
const GREEN = "\x1b[32m";
|
|
9
|
+
const YELLOW = "\x1b[33m";
|
|
10
|
+
const MAGENTA = "\x1b[35m";
|
|
11
|
+
const WHITE = "\x1b[37m";
|
|
12
|
+
|
|
13
|
+
const banner = `
|
|
14
|
+
${ CYAN }${ BRIGHT }
|
|
15
|
+
_ __ _ _ _ ${ MAGENTA } ____ ___ _
|
|
16
|
+
${ CYAN } | |/ /(_) | | (_) ${ MAGENTA }/ ___| / _ \\| |
|
|
17
|
+
${ CYAN } | ' / _ _ __ ___| |_ _ ___ ${ MAGENTA }\\___ \\| | | | |
|
|
18
|
+
${ CYAN } | < | | '_ \\ / _ \\ __| |/ __| ${ MAGENTA }___) | |_| | |___
|
|
19
|
+
${ CYAN } | . \\ | | | | | __/ |_| | (__ ${ MAGENTA }|____/ \\__\\_\\_____|
|
|
20
|
+
${ CYAN } |_|\\_\\|_|_| |_|\\___|\\__|_|\\___| ${ RESET }
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
console.log(banner);
|
|
24
|
+
console.log(`${ GREEN }${ BRIGHT } Package successfully Installed ✨${ RESET }\n`);
|
|
25
|
+
|
|
26
|
+
console.log(`${ WHITE }Please auto generate the schema using the following commands:${ RESET }\n`);
|
|
27
|
+
|
|
28
|
+
console.log(`${ YELLOW }# PostgreSQL (Default)${ RESET }`);
|
|
29
|
+
console.log(` ${ DIM }npx k-sql gen --connection "{CONNECTION_URL}"${ RESET }`);
|
|
30
|
+
console.log(` ${ DIM }OR${ RESET }`);
|
|
31
|
+
console.log(` ${ DIM }npx k-sql gen --type pg --host localhost --user postgres --db mydb${ RESET }\n`);
|
|
32
|
+
|
|
33
|
+
console.log(`${ YELLOW }# MySQL${ RESET }`);
|
|
34
|
+
console.log(` ${ DIM }npx k-sql gen --type mysql --host localhost --user root --db mydb${ RESET }\n`);
|
|
35
|
+
|
|
36
|
+
console.log(`${ YELLOW }# SQLite${ RESET }`);
|
|
37
|
+
console.log(` ${ DIM }npx k-sql gen --type sqlite --db ./dev.db${ RESET }\n`);
|
|
38
|
+
|
|
39
|
+
console.log(`${ DIM }-----------------------------------------------------------${ RESET }`);
|
|
40
|
+
console.log(`${ CYAN }Thanks for installing Kinetic-SQL 🙏${ RESET }`);
|
|
41
|
+
console.log(`${ WHITE }Please consider donating to our open collective to help me`);
|
|
42
|
+
console.log(`maintain this package and others that I am working on constantly.${ RESET }`);
|
|
43
|
+
console.log(`${ MAGENTA }🍻 Donate: https://opencollective.com/kinetic-ai ${ RESET }`);
|
|
44
|
+
console.log(`${ DIM }-----------------------------------------------------------${ RESET }\n`);
|