@ttoss/postgresdb 0.2.2 → 0.2.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 +77 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,6 +9,16 @@ pnpm add @ttoss/postgresdb
|
|
|
9
9
|
pnpm add -D @ttoss/postgresdb-cli
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
### ESM only
|
|
13
|
+
|
|
14
|
+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). Make sure to use it in an ESM environment.
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"type": "module"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
12
22
|
## Usage
|
|
13
23
|
|
|
14
24
|
### Setup the database
|
|
@@ -107,6 +117,73 @@ const user = await db.User.create({
|
|
|
107
117
|
|
|
108
118
|
All models are available in the `db` object.
|
|
109
119
|
|
|
120
|
+
### Using in a monorepo
|
|
121
|
+
|
|
122
|
+
If you want to use in a monorepo by sharing the models between packages, you need to create some configurations to make it work.
|
|
123
|
+
|
|
124
|
+
#### On the `postgresdb` package
|
|
125
|
+
|
|
126
|
+
1. Create your `postgresdb` package following the steps above.
|
|
127
|
+
|
|
128
|
+
1. Exports your main file in the `package.json` file:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"type": "module",
|
|
133
|
+
"exports": "./src/index.ts"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
1. Create a new file called `src/index.ts` with the following content to exports the `models` you've created:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
export * as models from './models';
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
_We recommend to not export the `db` object in this file because you may want to use different configurations in different packages._
|
|
144
|
+
|
|
145
|
+
#### On the other packages
|
|
146
|
+
|
|
147
|
+
1. Install `@ttoss/postgresdb` package:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
pnpm add @ttoss/postgresdb
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
1. Add your `postgresdb` package as a dependency. In the case you're using PNPM, you can use the [workspace protocol](https://pnpm.io/workspaces#workspace-protocol-workspace):
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"dependencies": {
|
|
158
|
+
"@yourproject/postgresdb": "workspace:^"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
1. Include the `postgresdb` package in the `include` field of the `tsconfig.json` file:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"include": ["src", "../postgresdb/src"]
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
_This way, you can import the models using the `@yourproject/postgresdb` package._
|
|
172
|
+
|
|
173
|
+
1. Create a new file called `src/db.ts` with the following content:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { initialize } from '@ttoss/postgresdb';
|
|
177
|
+
import { models } from '@yourproject/postgresdb';
|
|
178
|
+
|
|
179
|
+
export const db = initialize({
|
|
180
|
+
models,
|
|
181
|
+
// other configurations
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
1. Use the `db` object to interact with the database.
|
|
186
|
+
|
|
110
187
|
## API
|
|
111
188
|
|
|
112
189
|
### `initialize(options: InitializeOptions): db`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/postgresdb",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "A library to handle PostgreSQL database connections and queries",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
|
-
"tsup": "^8.3.
|
|
34
|
-
"@ttoss/config": "^1.34.
|
|
33
|
+
"tsup": "^8.3.5",
|
|
34
|
+
"@ttoss/config": "^1.34.2"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"database",
|