-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(drizzle): add basic support for drizzle-orm postgres (#179)
* feat(drizzle): add basic support for drizzle-orm postgres * feat(drizzle): update drizzle-orm package.json description * feat(drizzle): update drizzle-orm package.json description * feat(drizzle): remove copied changes
- Loading branch information
Showing
11 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/transactional-adapters/transactional-adapter-drizzle/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test.db |
3 changes: 3 additions & 0 deletions
3
packages/transactional-adapters/transactional-adapter-drizzle/CHANGES.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Changelog | ||
|
||
<!-- MONODEPLOY:BELOW --> |
5 changes: 5 additions & 0 deletions
5
packages/transactional-adapters/transactional-adapter-drizzle/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @nestjs-cls/transactional-adapter-drizzle-postgres | ||
|
||
Drizzle-orm (postgres) adapter for the `@nestjs-cls/transactional` plugin. | ||
|
||
### ➡️ [Go to the documentation website](https://papooch.github.io/nestjs-cls/plugins/available-plugins/transactional/knex-adapter) 📖 |
17 changes: 17 additions & 0 deletions
17
packages/transactional-adapters/transactional-adapter-drizzle/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
moduleFileExtensions: ['js', 'json', 'ts'], | ||
rootDir: '.', | ||
testRegex: '.*\\.spec\\.ts$', | ||
transform: { | ||
'^.+\\.ts$': [ | ||
'ts-jest', | ||
{ | ||
isolatedModules: true, | ||
maxWorkers: 1, | ||
}, | ||
], | ||
}, | ||
collectCoverageFrom: ['src/**/*.ts'], | ||
coverageDirectory: '../coverage', | ||
testEnvironment: 'node', | ||
}; |
73 changes: 73 additions & 0 deletions
73
packages/transactional-adapters/transactional-adapter-drizzle/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"name": "@nestjs-cls/transactional-adapter-drizzle", | ||
"version": "1.2.4", | ||
"description": "A drizzle-orm adapter for @nestjs-cls/transactional", | ||
"author": "papooch", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Papooch/nestjs-cls.git" | ||
}, | ||
"homepage": "https://papooch.github.io/nestjs-cls/", | ||
"keywords": [ | ||
"nest", | ||
"nestjs", | ||
"cls", | ||
"continuation-local-storage", | ||
"als", | ||
"AsyncLocalStorage", | ||
"async_hooks", | ||
"request context", | ||
"async context", | ||
"transaction", | ||
"transactional", | ||
"transactional decorator", | ||
"aop", | ||
"drizzle-orm", | ||
"drizzle" | ||
], | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"files": [ | ||
"dist/src/**/!(*.spec).d.ts", | ||
"dist/src/**/!(*.spec).js" | ||
], | ||
"scripts": { | ||
"prepack": "cp ../../../LICENSE ./LICENSE", | ||
"prebuild": "rimraf dist", | ||
"build": "tsc", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage" | ||
}, | ||
"peerDependencies": { | ||
"@nestjs-cls/transactional": "workspace:^2.4.2", | ||
"drizzle-orm": "*", | ||
"nestjs-cls": "workspace:^4.4.1" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^10.0.2", | ||
"@nestjs/common": "^10.3.7", | ||
"@nestjs/core": "^10.3.7", | ||
"@nestjs/testing": "^10.3.7", | ||
"@types/jest": "^28.1.2", | ||
"@types/node": "^18.0.0", | ||
"drizzle-orm": "^0.34.1", | ||
"jest": "^29.7.0", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rxjs": "^7.5.5", | ||
"sqlite3": "^5.1.7", | ||
"ts-jest": "^29.1.2", | ||
"ts-loader": "^9.3.0", | ||
"ts-node": "^10.8.1", | ||
"tsconfig-paths": "^4.0.0", | ||
"typescript": "5.0" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/transactional-adapters/transactional-adapter-drizzle/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/transactional-adapter-drizzle'; |
48 changes: 48 additions & 0 deletions
48
...sactional-adapters/transactional-adapter-drizzle/src/lib/transactional-adapter-drizzle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TransactionalAdapter } from "@nestjs-cls/transactional"; | ||
import type { PgTransactionConfig } from "drizzle-orm/pg-core"; | ||
import { PostgresJsDatabase } from "drizzle-orm/postgres-js"; | ||
|
||
export interface DrizzleOrmTransactionalAdapterOptions { | ||
/** | ||
* The injection token for the Drizzle instance. | ||
*/ | ||
drizzleInstanceToken: any; | ||
|
||
/** | ||
* Default options for the transaction. These will be merged with any transaction-specific options | ||
* passed to the `@Transactional` decorator or the `TransactionHost#withTransaction` method. | ||
*/ | ||
defaultTxOptions?: Partial<PgTransactionConfig>; | ||
} | ||
|
||
export class TransactionalAdapterDrizzleOrm | ||
implements | ||
TransactionalAdapter< | ||
PostgresJsDatabase<any>, | ||
PostgresJsDatabase<any>, | ||
PgTransactionConfig | ||
> | ||
{ | ||
connectionToken: any; | ||
|
||
defaultTxOptions?: Partial<PgTransactionConfig>; | ||
|
||
constructor(options: DrizzleOrmTransactionalAdapterOptions) { | ||
this.connectionToken = options.drizzleInstanceToken; | ||
this.defaultTxOptions = options.defaultTxOptions; | ||
} | ||
|
||
optionsFactory = (drizzleInstance: PostgresJsDatabase) => ({ | ||
wrapWithTransaction: async ( | ||
options: PgTransactionConfig, | ||
fn: (...args: any[]) => Promise<any>, | ||
setClient: (client?: PostgresJsDatabase) => void | ||
) => { | ||
return drizzleInstance.transaction(async (trx) => { | ||
setClient(trx); | ||
return fn(); | ||
}, options); | ||
}, | ||
getFallbackInstance: () => drizzleInstance | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
...ctional-adapters/transactional-adapter-drizzle/test/transactional-adapter-drizzle.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const DRIZZLE_TOKEN = 'DRIZZLE'; | ||
|
||
describe('TransactionalAdapter Drizzle', () => { | ||
it('Should be able to create a transactional adapter', async () => { | ||
return true; | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/transactional-adapters/transactional-adapter-drizzle/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "." | ||
}, | ||
"include": ["src/**/*.ts", "test/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters