@possumtech/sqlrite 0.1.1

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -0
  3. package/package.json +21 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 PossumTech Laboratories
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # sqlrite
2
+
3
+ SQL Done Right
4
+
5
+ ## About sqlrite
6
+
7
+ The sqlrite package is a modern node module that delivers an opinionated
8
+ alternative to ORMs.
9
+
10
+ ## Opinions
11
+
12
+ 1. **SQL First**: SQL is the best way to interact with data.
13
+
14
+ 2. **Standards**: Node is the standard for server-side web apps, and it now
15
+ contains a native sqlite module. Sqlite is the standard for SQL.
16
+
17
+ 3. **Simplicity**: It takes as much time to master an ORM as it would take to
18
+ just master SQL, and with worse performance. For all but the most distributed,
19
+ concurrent, and custom use cases, sqlite is the best choice.
20
+
21
+ 4. **Security**: Inline SQL is insecure, hard to maintain, and error-prone.
22
+
23
+ 5. **Separation**: SQL code should be in separate SQL files rather than
24
+ scattered throughout your JS codebase.
25
+
26
+ ## Solution
27
+
28
+ **SQL**
29
+
30
+ Add a `sql` directory to your project and include as many `.sql` files as you
31
+ wish, with whatever folder structure you like. Sqlrite will automatically load
32
+ them all.
33
+
34
+ Sqlrite automatically loads only two types of code, "transactions," and
35
+ "prepared statements." Transactions can contain multiple statements, and are
36
+ best for operations like creating tables, views, and indexes. Prepared
37
+ Statements are best for the queries you will be running.
38
+
39
+ **Example SQL File**
40
+
41
+ ```sql
42
+ -- TX: createEmployeeTable
43
+ CREATE TABLE IF NOT EXISTS employees (
44
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
45
+ name TEXT NOT NULL,
46
+ position TEXT NOT NULL,
47
+ salary REAL NOT NULL
48
+ );
49
+
50
+ -- PS: addEmployee
51
+ INSERT INTO employees (name, position, salary)
52
+ VALUES ($name, $position, $salary);
53
+
54
+ -- PS: getTopEmployee
55
+ SELECT name FROM employees ORDER BY salary DESC LIMIT 1;
56
+ ```
57
+
58
+ **Example Node File**
59
+
60
+ ```js
61
+ import sqlrite from "sqlrite";
62
+
63
+ const sql = new sqlrite();
64
+
65
+ (async () => {
66
+ await sql.createEmployeeTable();
67
+
68
+ await sql.addEmployee.run({ name: "John", position: "CEO", salary: 99999 });
69
+ await sql.addEmployee.run({ name: "Jane", position: "COO", salary: 49998 });
70
+ await sql.addEmployee.run({ name: "Jack", position: "CFO", salary: 49998 });
71
+ await sql.addEmployee.run({ name: "Jill", position: "CIO", salary: 49998 });
72
+
73
+ const employee = await sql.getTopEmployee.get();
74
+
75
+ console.log(employee.name);
76
+ })();
77
+ ```
78
+
79
+
80
+ ## Installation
81
+
82
+ Navigate to your project directory and run the following command:
83
+
84
+ ```bash
85
+ npm install sqlrite
86
+ ```
87
+
88
+ ## Configuration
89
+
90
+ ```js
91
+ import sqlrite from "sqlrite";
92
+
93
+ const sql = new sqlrite(options = {
94
+ // Custom SQLite database file path.
95
+ path: ":memory:",
96
+
97
+ // Path to your SQL directory.
98
+ dir: "./sql",
99
+ });
100
+ ```
101
+
102
+ Additional arguments to the
103
+ [native sqlite module](https://nodejs.org/api/sqlite.html) can be passed as
104
+ well.
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@possumtech/sqlrite",
3
+ "version": "0.1.1",
4
+ "description": "SQL Done Right",
5
+ "keywords": ["node", "sqlite", "sql", "orm", "database"],
6
+ "homepage": "https://github.com/possumtech/sqlrite#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/possumtech/sqlrite/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/possumtech/sqlrite.git"
13
+ },
14
+ "license": "MIT",
15
+ "author": "@wikitopian",
16
+ "type": "module",
17
+ "main": "sqlrite.js",
18
+ "scripts": {
19
+ "test": "node ./test/test.js"
20
+ }
21
+ }