@carno.js/orm 1.0.0 → 1.0.2
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/LICENSE +673 -673
- package/dist/driver/bun-mysql.driver.js +7 -7
- package/dist/driver/bun-pg.driver.js +30 -30
- package/package.json +2 -2
|
@@ -236,13 +236,13 @@ class BunMysqlDriver extends bun_driver_base_1.BunDriverBase {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
async constraints(tableName, options) {
|
|
239
|
-
const result = await this.sql.unsafe(`SELECT
|
|
240
|
-
CONSTRAINT_NAME as index_name,
|
|
241
|
-
CONCAT('REFERENCES \`', REFERENCED_TABLE_NAME, '\` (\`', REFERENCED_COLUMN_NAME, '\`)') as consdef,
|
|
242
|
-
'FOREIGN KEY' as constraint_type
|
|
243
|
-
FROM information_schema.KEY_COLUMN_USAGE
|
|
244
|
-
WHERE TABLE_NAME = '${tableName}'
|
|
245
|
-
AND TABLE_SCHEMA = DATABASE()
|
|
239
|
+
const result = await this.sql.unsafe(`SELECT
|
|
240
|
+
CONSTRAINT_NAME as index_name,
|
|
241
|
+
CONCAT('REFERENCES \`', REFERENCED_TABLE_NAME, '\` (\`', REFERENCED_COLUMN_NAME, '\`)') as consdef,
|
|
242
|
+
'FOREIGN KEY' as constraint_type
|
|
243
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
244
|
+
WHERE TABLE_NAME = '${tableName}'
|
|
245
|
+
AND TABLE_SCHEMA = DATABASE()
|
|
246
246
|
AND REFERENCED_TABLE_NAME IS NOT NULL`);
|
|
247
247
|
return result.map((row) => {
|
|
248
248
|
return {
|
|
@@ -199,8 +199,8 @@ class BunPgDriver extends bun_driver_base_1.BunDriverBase {
|
|
|
199
199
|
}
|
|
200
200
|
async index(tableName, options) {
|
|
201
201
|
const schema = (options && options.schema) || 'public';
|
|
202
|
-
let result = await this.sql.unsafe(`SELECT indexname AS index_name, indexdef AS column_name, tablename AS table_name
|
|
203
|
-
FROM pg_indexes
|
|
202
|
+
let result = await this.sql.unsafe(`SELECT indexname AS index_name, indexdef AS column_name, tablename AS table_name
|
|
203
|
+
FROM pg_indexes
|
|
204
204
|
WHERE tablename = '${tableName}' AND schemaname = '${schema}'`);
|
|
205
205
|
result = result.filter((row) => row.index_name.includes('_pkey') || !row.column_name.includes('UNIQUE INDEX'));
|
|
206
206
|
return result.map((row) => {
|
|
@@ -213,30 +213,30 @@ class BunPgDriver extends bun_driver_base_1.BunDriverBase {
|
|
|
213
213
|
}
|
|
214
214
|
async constraints(tableName, options) {
|
|
215
215
|
const schema = (options && options.schema) || 'public';
|
|
216
|
-
const result = await this.sql.unsafe(`SELECT
|
|
217
|
-
conname AS index_name,
|
|
218
|
-
pg_get_constraintdef(pg_constraint.oid) as consdef,
|
|
219
|
-
CASE contype
|
|
220
|
-
WHEN 'c' THEN 'CHECK'
|
|
221
|
-
WHEN 'f' THEN 'FOREIGN KEY'
|
|
222
|
-
WHEN 'p' THEN 'PRIMARY KEY'
|
|
223
|
-
WHEN 'u' THEN 'UNIQUE'
|
|
224
|
-
WHEN 't' THEN 'TRIGGER'
|
|
225
|
-
WHEN 'x' THEN 'EXCLUSION'
|
|
226
|
-
ELSE 'UNKNOWN'
|
|
227
|
-
END AS constraint_type
|
|
228
|
-
FROM pg_constraint
|
|
229
|
-
where conrelid = (
|
|
230
|
-
SELECT oid
|
|
231
|
-
FROM pg_class
|
|
232
|
-
WHERE relname = '${tableName}'
|
|
233
|
-
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '${schema}')
|
|
234
|
-
)
|
|
235
|
-
AND conkey @> ARRAY(
|
|
236
|
-
SELECT attnum
|
|
237
|
-
FROM pg_attribute
|
|
238
|
-
WHERE attrelid = conrelid
|
|
239
|
-
AND attname = '${schema}'
|
|
216
|
+
const result = await this.sql.unsafe(`SELECT
|
|
217
|
+
conname AS index_name,
|
|
218
|
+
pg_get_constraintdef(pg_constraint.oid) as consdef,
|
|
219
|
+
CASE contype
|
|
220
|
+
WHEN 'c' THEN 'CHECK'
|
|
221
|
+
WHEN 'f' THEN 'FOREIGN KEY'
|
|
222
|
+
WHEN 'p' THEN 'PRIMARY KEY'
|
|
223
|
+
WHEN 'u' THEN 'UNIQUE'
|
|
224
|
+
WHEN 't' THEN 'TRIGGER'
|
|
225
|
+
WHEN 'x' THEN 'EXCLUSION'
|
|
226
|
+
ELSE 'UNKNOWN'
|
|
227
|
+
END AS constraint_type
|
|
228
|
+
FROM pg_constraint
|
|
229
|
+
where conrelid = (
|
|
230
|
+
SELECT oid
|
|
231
|
+
FROM pg_class
|
|
232
|
+
WHERE relname = '${tableName}'
|
|
233
|
+
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '${schema}')
|
|
234
|
+
)
|
|
235
|
+
AND conkey @> ARRAY(
|
|
236
|
+
SELECT attnum
|
|
237
|
+
FROM pg_attribute
|
|
238
|
+
WHERE attrelid = conrelid
|
|
239
|
+
AND attname = '${schema}'
|
|
240
240
|
)`);
|
|
241
241
|
return result.map((row) => {
|
|
242
242
|
return {
|
|
@@ -247,10 +247,10 @@ class BunPgDriver extends bun_driver_base_1.BunDriverBase {
|
|
|
247
247
|
});
|
|
248
248
|
}
|
|
249
249
|
async getEnums(tableName, schema) {
|
|
250
|
-
const result = await this.sql.unsafe(`SELECT e.enumlabel as label, t.typname as type
|
|
251
|
-
FROM pg_type t
|
|
252
|
-
JOIN pg_enum e ON t.oid = e.enumtypid
|
|
253
|
-
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
250
|
+
const result = await this.sql.unsafe(`SELECT e.enumlabel as label, t.typname as type
|
|
251
|
+
FROM pg_type t
|
|
252
|
+
JOIN pg_enum e ON t.oid = e.enumtypid
|
|
253
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
|
254
254
|
WHERE n.nspname = '${schema}'`);
|
|
255
255
|
return result.map((row) => {
|
|
256
256
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carno.js/orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A simple ORM for Carno.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": "
|
|
58
|
+
"gitHead": "963e66fb0ac345fbc71c8cc81c73c71eb160d0d5"
|
|
59
59
|
}
|