@jayfong/x-server 2.1.3 → 2.1.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.
|
@@ -43,3 +43,18 @@ function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
|
|
|
43
43
|
// @endindex
|
|
44
44
|
|
|
45
45
|
export * from '@prisma/client'
|
|
46
|
+
|
|
47
|
+
export const startTransaction = <T>(
|
|
48
|
+
cb: (models: {
|
|
49
|
+
[K in ModelName]: typeof import('../../src/models')[`${K}Model`]
|
|
50
|
+
}) => Promise<T>,
|
|
51
|
+
): Promise<T> => {
|
|
52
|
+
return prismaClient.$transaction(async tx => {
|
|
53
|
+
const _models = require('../../src/models')
|
|
54
|
+
const cache = Object.create(null)
|
|
55
|
+
return cb({
|
|
56
|
+
// @index('../.prisma/client/index.d.ts', /(?<=const ModelName:).+?(?=\})/s, /(\S+?):/g, (m, _) => `get ${_.camel(m[1])}() { return cache.${_.camel(m[1])} || (cache.${_.camel(m[1])} = _models.${_.camel(m[1])}Model.transactionify(tx)) }, `)
|
|
57
|
+
// @endindex
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}
|
|
@@ -43,3 +43,18 @@ function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
|
|
|
43
43
|
// @endindex
|
|
44
44
|
|
|
45
45
|
export * from '@prisma/client'
|
|
46
|
+
|
|
47
|
+
export const startTransaction = <T>(
|
|
48
|
+
cb: (models: {
|
|
49
|
+
[K in ModelName]: typeof import('../../src/models')[`${K}Model`]
|
|
50
|
+
}) => Promise<T>,
|
|
51
|
+
): Promise<T> => {
|
|
52
|
+
return prismaClient.$transaction(async tx => {
|
|
53
|
+
const _models = require('../../src/models')
|
|
54
|
+
const cache = Object.create(null)
|
|
55
|
+
return cb({
|
|
56
|
+
// @index('../.prisma/client/index.d.ts', /(?<=const ModelName:).+?(?=\})/s, /(\S+?):/g, (m, _) => `get ${_.camel(m[1])}() { return cache.${_.camel(m[1])} || (cache.${_.camel(m[1])} = _models.${_.camel(m[1])}Model.transactionify(tx)) }, `)
|
|
57
|
+
// @endindex
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}
|