@open-kingdom/shared-backend-data-access-database-setup 0.0.2-0
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
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# data-access-database-setup
|
|
2
|
+
|
|
3
|
+
This library provides a configurable database setup module for NestJS applications using Drizzle ORM with SQLite.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Dynamic module configuration for database setup
|
|
8
|
+
- Configurable schema injection
|
|
9
|
+
- SQLite database configuration with Drizzle ORM
|
|
10
|
+
- Example schema implementation
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Basic Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { Module } from '@nestjs/common';
|
|
18
|
+
import { DatabaseSetupModule } from '@open-kingdom/shared-backend-data-access-database-setup';
|
|
19
|
+
import { mySchema } from './my-schema';
|
|
20
|
+
|
|
21
|
+
@Module({
|
|
22
|
+
imports: [
|
|
23
|
+
DatabaseSetupModule.register({
|
|
24
|
+
schema: mySchema,
|
|
25
|
+
tag: 'MY_DB',
|
|
26
|
+
filename: 'my-app.db',
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
})
|
|
30
|
+
export class AppModule {}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Using the Example Schema
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Module } from '@nestjs/common';
|
|
37
|
+
import { DatabaseSetupModule, exampleSchema } from '@open-kingdom/shared-backend-data-access-database-setup';
|
|
38
|
+
|
|
39
|
+
@Module({
|
|
40
|
+
imports: [
|
|
41
|
+
DatabaseSetupModule.register({
|
|
42
|
+
schema: exampleSchema,
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
export class AppModule {}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Configuration Options
|
|
50
|
+
|
|
51
|
+
The `DatabaseSetupModule.register()` method accepts the following options:
|
|
52
|
+
|
|
53
|
+
- `schema`: **Required** - The database schema object containing table definitions
|
|
54
|
+
- `tag`: **Optional** - Database connection tag (defaults to 'DB_DEV')
|
|
55
|
+
- `filename`: **Optional** - SQLite database filename (defaults to 'demo.db')
|
|
56
|
+
|
|
57
|
+
## Schema Definition
|
|
58
|
+
|
|
59
|
+
Your schema should be defined using Drizzle ORM's table builders:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
|
|
63
|
+
|
|
64
|
+
export const users = sqliteTable('users', {
|
|
65
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
66
|
+
username: text('username').notNull().unique(),
|
|
67
|
+
email: text('email').notNull().unique(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const mySchema = {
|
|
71
|
+
users,
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Running unit tests
|
|
76
|
+
|
|
77
|
+
Run `nx test data-access-database-setup` to execute the unit tests via [Jest](https://jestjs.io).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,YAAY,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
export type SchemaConfig = Record<string, unknown>;
|
|
3
|
+
export interface DatabaseSetupModuleOptions {
|
|
4
|
+
schema: SchemaConfig;
|
|
5
|
+
filename?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class DatabaseSetupModule {
|
|
8
|
+
static register(options: DatabaseSetupModuleOptions): DynamicModule;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=data-access-database-setup.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-access-database-setup.module.d.ts","sourceRoot":"","sources":["../../src/lib/data-access-database-setup.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKvD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACnD,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBACa,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,0BAA0B,GAAG,aAAa;CAcpE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@open-kingdom/shared-backend-data-access-database-setup",
|
|
3
|
+
"version": "0.0.2-0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
".": {
|
|
10
|
+
"development": "./src/index.ts",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"!**/*.tsbuildinfo"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"tslib": "^2.3.0",
|
|
25
|
+
"@knaadh/nestjs-drizzle-better-sqlite3": "^1.2.0",
|
|
26
|
+
"drizzle-orm": "^0.44.5"
|
|
27
|
+
},
|
|
28
|
+
"nx": {
|
|
29
|
+
"name": "@open-kingdom/shared-backend-data-access-database-setup",
|
|
30
|
+
"targets": {
|
|
31
|
+
"build": {
|
|
32
|
+
"executor": "@nx/js:tsc",
|
|
33
|
+
"outputs": [
|
|
34
|
+
"{options.outputPath}"
|
|
35
|
+
],
|
|
36
|
+
"options": {
|
|
37
|
+
"outputPath": "dist/libs/shared/backend/data-access-database-setup",
|
|
38
|
+
"tsConfig": "libs/shared/backend/data-access-database-setup/tsconfig.lib.json",
|
|
39
|
+
"packageJson": "libs/shared/backend/data-access-database-setup/package.json",
|
|
40
|
+
"main": "libs/shared/backend/data-access-database-setup/src/index.ts",
|
|
41
|
+
"assets": [
|
|
42
|
+
"libs/shared/backend/data-access-database-setup/*.md"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"tags": [
|
|
48
|
+
"type:data-access",
|
|
49
|
+
"scope:shared",
|
|
50
|
+
"environment:backend"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|