@dbcube/query-builder 0.0.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.
package/.npmignore ADDED
@@ -0,0 +1,51 @@
1
+ # Directories
2
+ examples
3
+
4
+ # Ignorar dependencias y configuraciones de desarrollo
5
+ node_modules/
6
+ npm-debug.log*
7
+ yarn-debug.log*
8
+ yarn-error.log*
9
+
10
+ # Ignorar carpetas y archivos irrelevantes
11
+ .vscode/
12
+ .lh
13
+ .idea/
14
+ .DS_Store
15
+ Thumbs.db
16
+ *.log
17
+
18
+ # Ignorar configuraciones del proyecto
19
+ .env
20
+ .env.*.local
21
+ package-lock.json
22
+
23
+ # Ignorar archivos del sistema
24
+ *.swp
25
+ *.swo
26
+ *.tmp
27
+ *.temp
28
+
29
+ # Ignorar carpetas de trabajo
30
+ temp/
31
+ logs/
32
+ debug/
33
+
34
+ # Ignorar archivos de compilación
35
+ src/
36
+ tsconfig.json
37
+ tsconfig.tsbuildinfo
38
+
39
+ # Ignorar pruebas y configuraciones
40
+ tests/
41
+ __tests__/
42
+ __mocks__/
43
+ coverage/
44
+ jest.config.js
45
+
46
+ # Ignorar documentación o ejemplos no necesarios
47
+ docs/
48
+ examples/
49
+
50
+ # Asegurarse de incluir solo lo esencial
51
+ !.npmignore
@@ -0,0 +1,9 @@
1
+ ## Colaboración
2
+
3
+ Si deseas contribuir a este proyecto, sigue estos pasos:
4
+
5
+ 1. Haz un fork del repositorio.
6
+ 2. Crea una nueva rama (`git checkout -b feature/nueva-caracteristica`).
7
+ 3. Realiza tus cambios y haz commit de ellos (`git commit -am 'Añadir nueva característica'`).
8
+ 4. Sube tu rama (`git push origin feature/nueva-caracteristica`).
9
+ 5. Abre un Pull Request.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Albert Araya - Dbcube
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,134 @@
1
+ # query-builder
2
+
3
+ The DBCube Query Builder is a lightweight, flexible, and fluent library for building queries across multiple database engines, including MySQL, PostgreSQL, SQLite, and MongoDB, using JavaScript/Node.js.
4
+
5
+ Its agnostic design allows you to generate data manipulation (DML) and data definition (DDL) operations with a clean, chainable syntax—without sacrificing power or expressiveness.
6
+
7
+ It’s designed to work seamlessly in both SQL and NoSQL environments, providing a consistent abstraction layer across different storage technologies while still leveraging the native capabilities of each engine.
8
+
9
+ ## Features
10
+
11
+ - **Fluent API** for building SQL queries
12
+ - **Type-safe** query construction
13
+ - **Support for SELECT, INSERT, UPDATE, DELETE**
14
+ - **Advanced WHERE conditions** (AND, OR, groups, BETWEEN, IN, NULL checks)
15
+ - **JOINs**: INNER, LEFT, RIGHT
16
+ - **Aggregations**: COUNT, SUM, AVG, MAX, MIN
17
+ - **Ordering, Grouping, Distinct, Pagination**
18
+ - **Column management** (future extension)
19
+ - **Promise-based asynchronous API**
20
+ - **Singleton connection management**
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @dbcube/query-builder
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```typescript
31
+ import Database from "@dbcube/query-builder";
32
+
33
+ const db = new Database("my_database");
34
+
35
+ // Select all users
36
+ const users = await db.table("users").get();
37
+
38
+ // Select users with conditions
39
+ const activeUsers = await db
40
+ .table("users")
41
+ .where("status", "=", "active")
42
+ .orderBy("created_at", "DESC")
43
+ .limit(10)
44
+ .get();
45
+
46
+ // Insert new users
47
+ await db
48
+ .table("users")
49
+ .insert([{ name: "John", email: "john@example.com", age: 30 }]);
50
+
51
+ // Update a user
52
+ await db.table("users").where("id", "=", 1).update({ status: "inactive" });
53
+
54
+ // Delete users
55
+ await db.table("users").where("status", "=", "deleted").delete();
56
+ ```
57
+
58
+ ## API Documentation
59
+
60
+ ### Database
61
+
62
+ #### `new Database(name: string)`
63
+
64
+ Creates a new database connection instance.
65
+
66
+ #### `table(tableName: string): Table`
67
+
68
+ Returns a Table instance for building queries on the specified table.
69
+
70
+ ### Table
71
+
72
+ #### Query Methods
73
+
74
+ - `select(fields?: string[])`: Specify columns to select.
75
+ - `where(column, operator, value)`: Add a WHERE condition.
76
+ - `orWhere(column, operator, value)`: Add an OR WHERE condition.
77
+ - `whereGroup(callback)`: Grouped WHERE conditions.
78
+ - `whereBetween(column, [min, max])`: WHERE BETWEEN condition.
79
+ - `whereIn(column, values)`: WHERE IN condition.
80
+ - `whereNull(column)`: WHERE IS NULL condition.
81
+ - `whereNotNull(column)`: WHERE IS NOT NULL condition.
82
+ - `join(table, column1, operator, column2)`: INNER JOIN.
83
+ - `leftJoin(table, column1, operator, column2)`: LEFT JOIN.
84
+ - `rightJoin(table, column1, operator, column2)`: RIGHT JOIN.
85
+ - `orderBy(column, direction)`: ORDER BY clause.
86
+ - `groupBy(column)`: GROUP BY clause.
87
+ - `distinct()`: DISTINCT clause.
88
+ - `count(column?)`: COUNT aggregation.
89
+ - `sum(column)`: SUM aggregation.
90
+ - `avg(column)`: AVG aggregation.
91
+ - `max(column)`: MAX aggregation.
92
+ - `min(column)`: MIN aggregation.
93
+ - `limit(number)`: LIMIT clause.
94
+ - `page(number)`: Pagination (requires limit).
95
+
96
+ #### Execution Methods
97
+
98
+ - `get()`: Execute and return all matching rows.
99
+ - `first()`: Execute and return the first matching row.
100
+ - `find(value, column?)`: Find a row by column value (default: id).
101
+ - `insert(data)`: Insert one or more rows.
102
+ - `update(data)`: Update rows matching the conditions.
103
+ - `delete()`: Delete rows matching the conditions.
104
+
105
+ ## Example Usage
106
+
107
+ ```typescript
108
+ // Complex query with joins, grouping, and aggregation
109
+ const results = await db
110
+ .table("orders")
111
+ .join("users", "orders.user_id", "=", "users.id")
112
+ .where("orders.status", "=", "completed")
113
+ .groupBy("users.country")
114
+ .sum("orders.total")
115
+ .orderBy("sum", "DESC")
116
+ .limit(5)
117
+ .get();
118
+ ```
119
+
120
+ ## Error Handling
121
+
122
+ All methods throw descriptive errors for invalid usage, such as missing WHERE conditions on update/delete, or invalid data types.
123
+
124
+ ## License
125
+
126
+ This project is licensed under the MIT License.
127
+
128
+ ## Contributing
129
+
130
+ Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
131
+
132
+ ## About
133
+
134
+ dbcube-query-builder is part of the dbcube ecosystem, designed to provide a robust and flexible query building experience for modern Node.js applications.