@starbemtech/star-db-query-builder 1.0.21 → 1.0.23
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 +183 -8
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/index.html +1 -1
- package/index.d.ts +8 -3
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -1,12 +1,187 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NodeJS Star DB Query Builder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
🎉 Welcome to the NodeJS Database Library! This library provides a set of robust methods to interact with your database seamlessly. With TypeScript support, it ensures type safety and great developer experience.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
$ pnpm link global
|
|
5
|
+
## Features
|
|
7
6
|
|
|
8
|
-
-
|
|
9
|
-
|
|
7
|
+
- **TypeScript Declarations**: Ensure type safety and better autocompletion in your IDE.
|
|
8
|
+
- **Flexible Configuration**: Easily initialize and configure the database client.
|
|
9
|
+
- **Comprehensive CRUD Operations**: Perform Create, Read, Update, Delete operations with ease.
|
|
10
|
+
- **Join Queries**: Execute complex join queries effortlessly.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
// Use npm
|
|
16
|
+
$ npm install star-db-query-builder
|
|
17
|
+
|
|
18
|
+
// Use yarn
|
|
19
|
+
$ yarn add star-db-query-builder
|
|
20
|
+
|
|
21
|
+
// Use pnpm
|
|
22
|
+
$ pnpm install star-db-query-builder
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Initialization
|
|
28
|
+
|
|
29
|
+
First, initialize the database with the appropriate configuration.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { initDb, getDbClient } from 'star-db-query-builder';
|
|
33
|
+
|
|
34
|
+
// Use PostgresSQL
|
|
35
|
+
initDb({
|
|
36
|
+
type: 'pg',
|
|
37
|
+
options: {
|
|
38
|
+
connectionURL: 'YOUR POSTGRES CONNECTION URL'
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// User MySQL
|
|
43
|
+
initDb({
|
|
44
|
+
type: 'mysql',
|
|
45
|
+
options: {
|
|
46
|
+
url: 'YOUR MYSQL CONNECTION URL'
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// In your service, create an instance of getDbClient
|
|
51
|
+
const dbClient = getDbClient();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Methods
|
|
55
|
+
|
|
56
|
+
#### findFirst
|
|
57
|
+
|
|
58
|
+
Retrieve the first matching record from a table.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { findFirst } from 'star-db-query-builder';
|
|
62
|
+
|
|
63
|
+
const result = await findFirst({
|
|
64
|
+
tableName: 'users',
|
|
65
|
+
dbClient,
|
|
66
|
+
select: ['id', 'name', 'email'],
|
|
67
|
+
where: {
|
|
68
|
+
id: { operator: '=', value: 1 }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(result);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### findMany
|
|
76
|
+
|
|
77
|
+
Retrieve multiple records from a table.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { findMany } from 'star-db-query-builder';
|
|
81
|
+
|
|
82
|
+
const results = await findMany({
|
|
83
|
+
tableName: 'users',
|
|
84
|
+
dbClient,
|
|
85
|
+
select: ['id', 'name', 'email'],
|
|
86
|
+
where: {
|
|
87
|
+
status: { operator: '= ', value: 'active' }
|
|
88
|
+
},
|
|
89
|
+
limit: 10,
|
|
90
|
+
offset: 0,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
console.log(results);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### insert
|
|
97
|
+
|
|
98
|
+
Insert a new record into a table.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { insert } from 'star-db-query-builder';
|
|
102
|
+
|
|
103
|
+
const newUser = { name: 'John Doe', email: 'john@example.com' };
|
|
104
|
+
|
|
105
|
+
const insertedUser = await insert({
|
|
106
|
+
tableName: 'users',
|
|
107
|
+
dbClient,
|
|
108
|
+
data: newUser,
|
|
109
|
+
returning: ['id', 'name', 'email'],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
console.log(insertedUser);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### update
|
|
116
|
+
|
|
117
|
+
Update an existing record in a table.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { update } from 'star-db-query-builder';
|
|
121
|
+
|
|
122
|
+
const updatedUser = { name: 'John Smith' };
|
|
123
|
+
|
|
124
|
+
const result = await update({
|
|
125
|
+
tableName: 'users',
|
|
126
|
+
dbClient,
|
|
127
|
+
id: 1,
|
|
128
|
+
data: updatedUser,
|
|
129
|
+
returning: ['id', 'name', 'email'],
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
console.log(result);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### deleteOne
|
|
136
|
+
|
|
137
|
+
Delete a record from a table.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { deleteOne } from 'star-db-query-builder';
|
|
141
|
+
|
|
142
|
+
await deleteOne({
|
|
143
|
+
tableName: 'users',
|
|
144
|
+
dbClient,
|
|
145
|
+
id: 1,
|
|
146
|
+
permanently: true,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
console.log('User deleted');
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### joins
|
|
153
|
+
|
|
154
|
+
Execute a join query.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { joins } from 'star-db-query-builder';
|
|
158
|
+
|
|
159
|
+
const joinResults = await joins({
|
|
160
|
+
tableName: 'orders',
|
|
161
|
+
dbClient,
|
|
162
|
+
select: ['orders.id', 'users.name'],
|
|
163
|
+
joins: [
|
|
164
|
+
{
|
|
165
|
+
table: 'users',
|
|
166
|
+
on: { 'orders.userId': 'users.id' },
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
where: {
|
|
170
|
+
JOINS: [
|
|
171
|
+
{
|
|
172
|
+
'users.id': { operator: '=', value: exist.user_id }
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
console.log(joinResults);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
This project is licensed under the MIT License.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
👨💻 Happy Coding!
|
package/coverage/clover.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<coverage generated="
|
|
3
|
-
<project timestamp="
|
|
2
|
+
<coverage generated="1720095645093" clover="3.2.0">
|
|
3
|
+
<project timestamp="1720095645093" name="All files">
|
|
4
4
|
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" loc="0" ncloc="0" packages="0" files="0" classes="0"/>
|
|
5
5
|
</project>
|
|
6
6
|
</coverage>
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
87
87
|
Code coverage generated by
|
|
88
88
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
89
|
-
at 2024-
|
|
89
|
+
at 2024-07-04T12:20:45.089Z
|
|
90
90
|
</div>
|
|
91
91
|
<script src="prettify.js"></script>
|
|
92
92
|
<script>
|
package/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare function findMany<T>({
|
|
|
22
22
|
groupBy,
|
|
23
23
|
orderBy,
|
|
24
24
|
limit,
|
|
25
|
+
offset,
|
|
25
26
|
}: QueryParams<T>): Promise<T[]>
|
|
26
27
|
|
|
27
28
|
export declare function insert<P, R>({
|
|
@@ -46,10 +47,14 @@ export declare function deleteOne<T>({
|
|
|
46
47
|
permanently,
|
|
47
48
|
}: QueryParams<T> & { permanently?: boolean }): Promise<void>
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
export declare function getByUserAndSubscription<T>({
|
|
50
|
+
export declare function joins<T>({
|
|
51
51
|
tableName,
|
|
52
52
|
dbClient,
|
|
53
53
|
select,
|
|
54
|
+
joins,
|
|
54
55
|
where,
|
|
55
|
-
|
|
56
|
+
groupBy,
|
|
57
|
+
orderBy,
|
|
58
|
+
limit,
|
|
59
|
+
offset,
|
|
60
|
+
}: QueryParams<T>): Promise<T[]>
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starbemtech/star-db-query-builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "A query builder to be used with mysql or postgres",
|
|
5
5
|
"author": "Julio Sousa <julio.sousa@starbem.app>",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
11
|
-
"pnpm": ">=8.6.7 <9"
|
|
10
|
+
"node": ">=18"
|
|
12
11
|
},
|
|
13
12
|
"scripts": {
|
|
14
13
|
"build": "tsc",
|
|
@@ -42,7 +41,6 @@
|
|
|
42
41
|
"eslint-config-prettier": "^9.1.0",
|
|
43
42
|
"eslint-plugin-jest": "^27.9.0",
|
|
44
43
|
"eslint-plugin-prettier": "^5.1.3",
|
|
45
|
-
"git-commit-msg-linter": "^5.0.7",
|
|
46
44
|
"husky": "^9.0.11",
|
|
47
45
|
"jest": "^29.7.0",
|
|
48
46
|
"lint-staged": "^15.2.2",
|
|
@@ -65,5 +63,6 @@
|
|
|
65
63
|
"hooks": {
|
|
66
64
|
"pre-commit": "lint-staged"
|
|
67
65
|
}
|
|
68
|
-
}
|
|
66
|
+
},
|
|
67
|
+
"packageManager": "pnpm@8.6.2"
|
|
69
68
|
}
|