@cheetah.js/orm 0.1.132 → 0.1.135

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.
@@ -217,13 +217,13 @@ class BunMysqlDriver extends bun_driver_base_1.BunDriverBase {
217
217
  });
218
218
  }
219
219
  async constraints(tableName, options) {
220
- const result = await this.sql.unsafe(`SELECT
221
- CONSTRAINT_NAME as index_name,
222
- CONCAT('REFERENCES \`', REFERENCED_TABLE_NAME, '\` (\`', REFERENCED_COLUMN_NAME, '\`)') as consdef,
223
- 'FOREIGN KEY' as constraint_type
224
- FROM information_schema.KEY_COLUMN_USAGE
225
- WHERE TABLE_NAME = '${tableName}'
226
- AND TABLE_SCHEMA = DATABASE()
220
+ const result = await this.sql.unsafe(`SELECT
221
+ CONSTRAINT_NAME as index_name,
222
+ CONCAT('REFERENCES \`', REFERENCED_TABLE_NAME, '\` (\`', REFERENCED_COLUMN_NAME, '\`)') as consdef,
223
+ 'FOREIGN KEY' as constraint_type
224
+ FROM information_schema.KEY_COLUMN_USAGE
225
+ WHERE TABLE_NAME = '${tableName}'
226
+ AND TABLE_SCHEMA = DATABASE()
227
227
  AND REFERENCED_TABLE_NAME IS NOT NULL`);
228
228
  return result.map((row) => {
229
229
  return {
@@ -182,8 +182,8 @@ class BunPgDriver extends bun_driver_base_1.BunDriverBase {
182
182
  }
183
183
  async index(tableName, options) {
184
184
  const schema = (options && options.schema) || 'public';
185
- let result = await this.sql.unsafe(`SELECT indexname AS index_name, indexdef AS column_name, tablename AS table_name
186
- FROM pg_indexes
185
+ let result = await this.sql.unsafe(`SELECT indexname AS index_name, indexdef AS column_name, tablename AS table_name
186
+ FROM pg_indexes
187
187
  WHERE tablename = '${tableName}' AND schemaname = '${schema}'`);
188
188
  result = result.filter((row) => row.index_name.includes('_pkey') || !row.column_name.includes('UNIQUE INDEX'));
189
189
  return result.map((row) => {
@@ -196,30 +196,30 @@ class BunPgDriver extends bun_driver_base_1.BunDriverBase {
196
196
  }
197
197
  async constraints(tableName, options) {
198
198
  const schema = (options && options.schema) || 'public';
199
- const result = await this.sql.unsafe(`SELECT
200
- conname AS index_name,
201
- pg_get_constraintdef(pg_constraint.oid) as consdef,
202
- CASE contype
203
- WHEN 'c' THEN 'CHECK'
204
- WHEN 'f' THEN 'FOREIGN KEY'
205
- WHEN 'p' THEN 'PRIMARY KEY'
206
- WHEN 'u' THEN 'UNIQUE'
207
- WHEN 't' THEN 'TRIGGER'
208
- WHEN 'x' THEN 'EXCLUSION'
209
- ELSE 'UNKNOWN'
210
- END AS constraint_type
211
- FROM pg_constraint
212
- where conrelid = (
213
- SELECT oid
214
- FROM pg_class
215
- WHERE relname = '${tableName}'
216
- AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '${schema}')
217
- )
218
- AND conkey @> ARRAY(
219
- SELECT attnum
220
- FROM pg_attribute
221
- WHERE attrelid = conrelid
222
- AND attname = '${schema}'
199
+ const result = await this.sql.unsafe(`SELECT
200
+ conname AS index_name,
201
+ pg_get_constraintdef(pg_constraint.oid) as consdef,
202
+ CASE contype
203
+ WHEN 'c' THEN 'CHECK'
204
+ WHEN 'f' THEN 'FOREIGN KEY'
205
+ WHEN 'p' THEN 'PRIMARY KEY'
206
+ WHEN 'u' THEN 'UNIQUE'
207
+ WHEN 't' THEN 'TRIGGER'
208
+ WHEN 'x' THEN 'EXCLUSION'
209
+ ELSE 'UNKNOWN'
210
+ END AS constraint_type
211
+ FROM pg_constraint
212
+ where conrelid = (
213
+ SELECT oid
214
+ FROM pg_class
215
+ WHERE relname = '${tableName}'
216
+ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '${schema}')
217
+ )
218
+ AND conkey @> ARRAY(
219
+ SELECT attnum
220
+ FROM pg_attribute
221
+ WHERE attrelid = conrelid
222
+ AND attname = '${schema}'
223
223
  )`);
224
224
  return result.map((row) => {
225
225
  return {
@@ -230,10 +230,10 @@ class BunPgDriver extends bun_driver_base_1.BunDriverBase {
230
230
  });
231
231
  }
232
232
  async getEnums(tableName, schema) {
233
- const result = await this.sql.unsafe(`SELECT e.enumlabel as label, t.typname as type
234
- FROM pg_type t
235
- JOIN pg_enum e ON t.oid = e.enumtypid
236
- JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
233
+ const result = await this.sql.unsafe(`SELECT e.enumlabel as label, t.typname as type
234
+ FROM pg_type t
235
+ JOIN pg_enum e ON t.oid = e.enumtypid
236
+ JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
237
237
  WHERE n.nspname = '${schema}'`);
238
238
  return result.map((row) => {
239
239
  return {
package/dist/orm.js CHANGED
@@ -48,6 +48,9 @@ let Orm = Orm_1 = class Orm {
48
48
  if (!this.driverInstance) {
49
49
  throw new Error('Driver instance not initialized');
50
50
  }
51
+ if (transaction_context_1.transactionContext.hasContext()) {
52
+ return operation(transaction_context_1.transactionContext.getContext());
53
+ }
51
54
  return this.driverInstance.transaction(async (tx) => {
52
55
  return transaction_context_1.transactionContext.run(tx, () => operation(tx));
53
56
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.132",
3
+ "version": "0.1.135",
4
4
  "description": "A simple ORM for Cheetah.js.",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -55,5 +55,5 @@
55
55
  "bun",
56
56
  "value-object"
57
57
  ],
58
- "gitHead": "a8b11c0105b55a7b3a987246a059573ec877ab81"
58
+ "gitHead": "640794a5fc98073f33a057b099658ee184371112"
59
59
  }
package/build.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { ConnectionSettings } from '@cheetah.js/orm/driver/driver.interface';
2
- declare const config: ConnectionSettings<any>;
3
- export default config;