ts-prorm-orm 1.1.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/CHANGELOG.md +1111 -0
- package/LICENSE +21 -0
- package/README.md +573 -0
- package/dist/audit/history-query.js +180 -0
- package/dist/audit/index.js +23 -0
- package/dist/audit/logger.js +236 -0
- package/dist/cache/cache-manager.js +84 -0
- package/dist/cache/index.js +16 -0
- package/dist/cache/redis-cluster-cache.js +557 -0
- package/dist/cli.js +2200 -0
- package/dist/compliance/audit-trail.js +68 -0
- package/dist/compliance/backup-verification.js +685 -0
- package/dist/compliance/breach-detector.js +505 -0
- package/dist/compliance/consent-record.js +227 -0
- package/dist/compliance/consent-versioning.js +331 -0
- package/dist/compliance/cross-border-log.js +530 -0
- package/dist/compliance/data-classifier.js +258 -0
- package/dist/compliance/data-lineage.js +565 -0
- package/dist/compliance/data-masker.js +303 -0
- package/dist/compliance/data-portability.js +265 -0
- package/dist/compliance/data-retention.js +195 -0
- package/dist/compliance/dsar-workflow.js +342 -0
- package/dist/compliance/field-encryption.js +223 -0
- package/dist/compliance/immutable-record.js +148 -0
- package/dist/compliance/index.js +260 -0
- package/dist/compliance/privacy-impact-assessment.js +364 -0
- package/dist/compliance/pseudonymization.js +269 -0
- package/dist/compliance/query-firewall.js +1182 -0
- package/dist/compliance/rate-limiter.js +580 -0
- package/dist/compliance/right-to-erasure.js +117 -0
- package/dist/compliance/row-level-security.js +246 -0
- package/dist/compliance/security-decorator.js +574 -0
- package/dist/compliance/security-monitor.js +525 -0
- package/dist/compliance/sensitive-data-discovery.js +476 -0
- package/dist/compliance/session-isolation.js +472 -0
- package/dist/compliance/tls-enforcer.js +108 -0
- package/dist/compliance/worm-storage.js +712 -0
- package/dist/connection-manager.js +198 -0
- package/dist/connection-pool.js +519 -0
- package/dist/decorators/audit.js +136 -0
- package/dist/decorators/belongs-to-many.js +115 -0
- package/dist/decorators/belongs-to.js +115 -0
- package/dist/decorators/check.js +435 -0
- package/dist/decorators/collate.js +329 -0
- package/dist/decorators/comment.js +205 -0
- package/dist/decorators/database-settings.js +236 -0
- package/dist/decorators/default.js +244 -0
- package/dist/decorators/encryption.js +235 -0
- package/dist/decorators/engine.js +97 -0
- package/dist/decorators/fk-constraints.js +594 -0
- package/dist/decorators/foreign-table.js +136 -0
- package/dist/decorators/generated.js +274 -0
- package/dist/decorators/has-many.js +127 -0
- package/dist/decorators/has-one.js +116 -0
- package/dist/decorators/hstore.js +129 -0
- package/dist/decorators/index.js +355 -0
- package/dist/decorators/json-column.js +83 -0
- package/dist/decorators/jsonb.js +101 -0
- package/dist/decorators/orm-decorators.js +425 -0
- package/dist/decorators/permissions.js +294 -0
- package/dist/decorators/procedure.js +210 -0
- package/dist/decorators/query-options.js +556 -0
- package/dist/decorators/range.js +167 -0
- package/dist/decorators/set-column.js +83 -0
- package/dist/decorators/spatial.js +114 -0
- package/dist/decorators/storage.js +580 -0
- package/dist/decorators/timezone.js +512 -0
- package/dist/decorators/trigger.js +90 -0
- package/dist/decorators/uuid.js +135 -0
- package/dist/decorators/view.js +258 -0
- package/dist/diagrams/chen-diagram.js +354 -0
- package/dist/diagrams/class-diagram.js +384 -0
- package/dist/diagrams/dependency-diagram.js +432 -0
- package/dist/diagrams/er-diagram.js +605 -0
- package/dist/diagrams/flow-diagram.js +394 -0
- package/dist/diagrams/gantt-diagram.js +411 -0
- package/dist/diagrams/index-diagram.js +353 -0
- package/dist/diagrams/index.js +184 -0
- package/dist/diagrams/migration-diagram.js +316 -0
- package/dist/diagrams/model-diagram.js +616 -0
- package/dist/diagrams/package-diagram.js +376 -0
- package/dist/diagrams/palette.js +85 -0
- package/dist/diagrams/relational-diagram.js +455 -0
- package/dist/diagrams/schemadoc-diagram.js +309 -0
- package/dist/diagrams/sequence-diagram.js +307 -0
- package/dist/diagrams/state-diagram.js +344 -0
- package/dist/diagrams/svg-dom.js +111 -0
- package/dist/diagrams/tree-diagram.js +250 -0
- package/dist/dialects/clickhouse/index.js +1742 -0
- package/dist/dialects/cockroachdb/index.js +4677 -0
- package/dist/dialects/cratedb/index.js +441 -0
- package/dist/dialects/databricks/index.js +517 -0
- package/dist/dialects/db2/index.js +2225 -0
- package/dist/dialects/dialect.js +720 -0
- package/dist/dialects/duckdb/index.js +2014 -0
- package/dist/dialects/exasol/index.js +357 -0
- package/dist/dialects/firebird/index.js +495 -0
- package/dist/dialects/greenplum/index.js +457 -0
- package/dist/dialects/hana/index.js +1741 -0
- package/dist/dialects/mariadb/index.js +3590 -0
- package/dist/dialects/mssql/index.js +2296 -0
- package/dist/dialects/mysql/index.js +4058 -0
- package/dist/dialects/oracle/index.js +2999 -0
- package/dist/dialects/postgres/index.js +5319 -0
- package/dist/dialects/query-stream-helper.js +152 -0
- package/dist/dialects/questdb/index.js +433 -0
- package/dist/dialects/redshift/index.js +2277 -0
- package/dist/dialects/singlestore/index.js +354 -0
- package/dist/dialects/snowflake/index.js +2082 -0
- package/dist/dialects/spanner/index.js +1768 -0
- package/dist/dialects/sqlite/index.js +3382 -0
- package/dist/dialects/tidb/index.js +377 -0
- package/dist/dialects/timescaledb/index.js +164 -0
- package/dist/dialects/trino/index.js +420 -0
- package/dist/dialects/turso/index.js +227 -0
- package/dist/dialects/vertica/index.js +317 -0
- package/dist/dialects/yugabytedb/index.js +424 -0
- package/dist/errors/index.js +472 -0
- package/dist/errors/utils.js +340 -0
- package/dist/errors.js +21 -0
- package/dist/extensions/catalog/cloud-warehouse-features.js +207 -0
- package/dist/extensions/catalog/mssql-features.js +147 -0
- package/dist/extensions/catalog/mysql-mariadb-plugins.js +229 -0
- package/dist/extensions/catalog/oracle-db2-features.js +196 -0
- package/dist/extensions/catalog/postgres-extensions.js +516 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/types.js +13 -0
- package/dist/foreign-data.js +173 -0
- package/dist/hooks/hooks-manager.js +350 -0
- package/dist/hooks/index.js +37 -0
- package/dist/index.js +463 -0
- package/dist/logging.js +335 -0
- package/dist/migrations/index.js +40 -0
- package/dist/migrations/migration.js +196 -0
- package/dist/migrations/migrator.js +411 -0
- package/dist/migrations/prormmigration.js +275 -0
- package/dist/migrations/query-interface.js +435 -0
- package/dist/migrations/seeder.js +353 -0
- package/dist/models/associations.js +852 -0
- package/dist/models/constraints.js +288 -0
- package/dist/models/data-types.js +2518 -0
- package/dist/models/decorators.js +445 -0
- package/dist/models/index.js +33 -0
- package/dist/models/indexes.js +531 -0
- package/dist/models/methods.js +382 -0
- package/dist/models/model-manager.js +103 -0
- package/dist/models/model.js +5349 -0
- package/dist/models/operators.js +67 -0
- package/dist/models/scopes.js +189 -0
- package/dist/models/typescript-types.js +26 -0
- package/dist/nosql/aerospike/index.js +205 -0
- package/dist/nosql/allegrograph/index.js +169 -0
- package/dist/nosql/arangodb/index.js +364 -0
- package/dist/nosql/azure-blob/index.js +206 -0
- package/dist/nosql/beanstalkd/index.js +231 -0
- package/dist/nosql/beequeue/index.js +210 -0
- package/dist/nosql/bigchaindb/index.js +195 -0
- package/dist/nosql/bigtable/index.js +224 -0
- package/dist/nosql/blazegraph/index.js +173 -0
- package/dist/nosql/bullmq/index.js +191 -0
- package/dist/nosql/cassandra/index.js +174 -0
- package/dist/nosql/chroma/index.js +190 -0
- package/dist/nosql/cloudflare-kv/index.js +220 -0
- package/dist/nosql/coherence/index.js +200 -0
- package/dist/nosql/cosmosdb/index.js +157 -0
- package/dist/nosql/couchbase/index.js +213 -0
- package/dist/nosql/dax/index.js +212 -0
- package/dist/nosql/deno-kv/index.js +206 -0
- package/dist/nosql/dgraph/index.js +171 -0
- package/dist/nosql/doris/index.js +169 -0
- package/dist/nosql/druid/index.js +162 -0
- package/dist/nosql/dynamodb/index.js +937 -0
- package/dist/nosql/elasticsearch/index.js +377 -0
- package/dist/nosql/etcd/index.js +502 -0
- package/dist/nosql/eventhubs/index.js +213 -0
- package/dist/nosql/eventstore/index.js +254 -0
- package/dist/nosql/faunadb/index.js +188 -0
- package/dist/nosql/firestore/index.js +177 -0
- package/dist/nosql/fluree/index.js +148 -0
- package/dist/nosql/fuseki/index.js +170 -0
- package/dist/nosql/gcs/index.js +172 -0
- package/dist/nosql/gearman/index.js +160 -0
- package/dist/nosql/geode/index.js +196 -0
- package/dist/nosql/graphdb/index.js +169 -0
- package/dist/nosql/graylog/index.js +188 -0
- package/dist/nosql/gridgain/index.js +171 -0
- package/dist/nosql/hazelcast/index.js +162 -0
- package/dist/nosql/hbase/index.js +230 -0
- package/dist/nosql/ignite/index.js +173 -0
- package/dist/nosql/immudb/index.js +184 -0
- package/dist/nosql/index.js +232 -0
- package/dist/nosql/infinispan/index.js +200 -0
- package/dist/nosql/influxdb/index.js +0 -0
- package/dist/nosql/kafka/index.js +234 -0
- package/dist/nosql/keyspaces/index.js +189 -0
- package/dist/nosql/kinesis/index.js +253 -0
- package/dist/nosql/leveldb/index.js +153 -0
- package/dist/nosql/lmdb/index.js +160 -0
- package/dist/nosql/loki/index.js +201 -0
- package/dist/nosql/marklogic/index.js +204 -0
- package/dist/nosql/materialize/index.js +145 -0
- package/dist/nosql/meilisearch/index.js +154 -0
- package/dist/nosql/memcached/index.js +223 -0
- package/dist/nosql/milvus/index.js +410 -0
- package/dist/nosql/minio/index.js +265 -0
- package/dist/nosql/momento/index.js +179 -0
- package/dist/nosql/mongodb/index.js +461 -0
- package/dist/nosql/nats/index.js +247 -0
- package/dist/nosql/nedb/index.js +164 -0
- package/dist/nosql/neo4j/index.js +450 -0
- package/dist/nosql/neptune/index.js +470 -0
- package/dist/nosql/nsq/index.js +200 -0
- package/dist/nosql/opensearch/index.js +186 -0
- package/dist/nosql/orientdb/index.js +175 -0
- package/dist/nosql/papertrail/index.js +200 -0
- package/dist/nosql/pinecone/index.js +0 -0
- package/dist/nosql/pinot/index.js +133 -0
- package/dist/nosql/pouchdb/index.js +172 -0
- package/dist/nosql/prometheus/index.js +174 -0
- package/dist/nosql/provendb/index.js +147 -0
- package/dist/nosql/pubsub/index.js +187 -0
- package/dist/nosql/pulsar/index.js +232 -0
- package/dist/nosql/qdrant/index.js +295 -0
- package/dist/nosql/qldb/index.js +192 -0
- package/dist/nosql/r2/index.js +281 -0
- package/dist/nosql/rabbitmq/index.js +237 -0
- package/dist/nosql/ravendb/index.js +175 -0
- package/dist/nosql/redis/index.js +607 -0
- package/dist/nosql/redpanda/index.js +237 -0
- package/dist/nosql/resque/index.js +203 -0
- package/dist/nosql/rethinkdb/index.js +232 -0
- package/dist/nosql/rocksdb/index.js +152 -0
- package/dist/nosql/rockset/index.js +126 -0
- package/dist/nosql/s3/index.js +298 -0
- package/dist/nosql/scylladb/index.js +178 -0
- package/dist/nosql/signoz/index.js +227 -0
- package/dist/nosql/sns/index.js +201 -0
- package/dist/nosql/solr/index.js +231 -0
- package/dist/nosql/splunk/index.js +227 -0
- package/dist/nosql/sqs/index.js +246 -0
- package/dist/nosql/stardog/index.js +169 -0
- package/dist/nosql/starrocks/index.js +170 -0
- package/dist/nosql/store.js +2 -0
- package/dist/nosql/sumologic/index.js +213 -0
- package/dist/nosql/surrealdb/index.js +179 -0
- package/dist/nosql/terminusdb/index.js +151 -0
- package/dist/nosql/tigergraph/index.js +469 -0
- package/dist/nosql/typesense/index.js +148 -0
- package/dist/nosql/unqlite/index.js +157 -0
- package/dist/nosql/upstash/index.js +167 -0
- package/dist/nosql/vercel-kv/index.js +166 -0
- package/dist/nosql/victoriametrics/index.js +213 -0
- package/dist/nosql/virtuoso/index.js +169 -0
- package/dist/nosql/weaviate/index.js +276 -0
- package/dist/operators/index.js +108 -0
- package/dist/operators.js +2690 -0
- package/dist/prisma-migrate/index.js +38 -0
- package/dist/prisma-migrate/migration-generator.js +125 -0
- package/dist/prisma-migrate/model-generator.js +172 -0
- package/dist/prisma-migrate/relations.js +100 -0
- package/dist/prisma-migrate/schema-parser.js +167 -0
- package/dist/prisma-migrate/type-mapper.js +40 -0
- package/dist/prorm.js +6832 -0
- package/dist/query-builders/cte-builder.js +80 -0
- package/dist/query-builders/functions/aggregate.js +390 -0
- package/dist/query-builders/functions/conditional.js +503 -0
- package/dist/query-builders/functions/datetime.js +695 -0
- package/dist/query-builders/functions/fulltext.js +439 -0
- package/dist/query-builders/functions/index.js +93 -0
- package/dist/query-builders/functions/json.js +427 -0
- package/dist/query-builders/functions/math.js +399 -0
- package/dist/query-builders/functions/string.js +518 -0
- package/dist/query-builders/functions/window.js +328 -0
- package/dist/query-builders/include-builder.js +323 -0
- package/dist/query-builders/index-expression-builder.js +242 -0
- package/dist/query-builders/index.js +161 -0
- package/dist/query-builders/insert-builder.js +164 -0
- package/dist/query-builders/model-helpers.js +38 -0
- package/dist/query-builders/order-limit-builder.js +239 -0
- package/dist/query-builders/sql-compiler.js +2040 -0
- package/dist/query-builders/subquery-builder.js +152 -0
- package/dist/query-builders/update-builder.js +182 -0
- package/dist/query-builders/view-builder.js +218 -0
- package/dist/query-builders/where-builder.js +1532 -0
- package/dist/query-interface.js +622 -0
- package/dist/query-optimizers/batch-optimizer.js +426 -0
- package/dist/query-optimizers/explain-plans.js +415 -0
- package/dist/query-optimizers/index.js +51 -0
- package/dist/query-optimizers/prepared-statement-cache.js +423 -0
- package/dist/query-optimizers/query-hints.js +438 -0
- package/dist/query-optimizers/query-optimizer.js +278 -0
- package/dist/query-optimizers/slow-query-logger.js +271 -0
- package/dist/replica-manager.js +507 -0
- package/dist/schema/index.js +15 -0
- package/dist/schema/migration-generator.js +374 -0
- package/dist/schema/schema-differ.js +549 -0
- package/dist/schema/types.js +6 -0
- package/dist/sql-constants.js +300 -0
- package/dist/sqlite-advanced.js +1047 -0
- package/dist/streams/index.js +12 -0
- package/dist/streams/transforms.js +178 -0
- package/dist/transaction.js +456 -0
- package/dist/types/index.js +180 -0
- package/dist/user-management.js +127 -0
- package/dist/utils/date.js +300 -0
- package/dist/utils/index.js +1079 -0
- package/dist/utils/string.js +161 -0
- package/dist/validators/index.js +19 -0
- package/dist/validators/validator.js +911 -0
- package/package.json +190 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Index Expression Builder
|
|
4
|
+
* Provides ORM-like way to create functional indexes
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.IndexExpressionBuilder = void 0;
|
|
8
|
+
exports.createIndexBuilder = createIndexBuilder;
|
|
9
|
+
const model_helpers_1 = require("./model-helpers");
|
|
10
|
+
/**
|
|
11
|
+
* Builder for index expressions
|
|
12
|
+
*/
|
|
13
|
+
class IndexExpressionBuilder {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.columns = [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Add a simple column to the index
|
|
19
|
+
*/
|
|
20
|
+
column(name, opts) {
|
|
21
|
+
this.columns.push({
|
|
22
|
+
name,
|
|
23
|
+
length: opts?.length,
|
|
24
|
+
order: opts?.order,
|
|
25
|
+
});
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Add a functional index using a column reference
|
|
30
|
+
*/
|
|
31
|
+
functional(column, opts) {
|
|
32
|
+
const modelName = opts?.model ? (0, model_helpers_1.getTableName)(opts.model) : undefined;
|
|
33
|
+
this.columns.push({
|
|
34
|
+
name: column,
|
|
35
|
+
expression: {
|
|
36
|
+
__type: 'column',
|
|
37
|
+
model: modelName,
|
|
38
|
+
column,
|
|
39
|
+
},
|
|
40
|
+
length: opts?.length,
|
|
41
|
+
order: opts?.order,
|
|
42
|
+
});
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Add LOWER(column) expression
|
|
47
|
+
*/
|
|
48
|
+
lower(column, opts) {
|
|
49
|
+
this.columns.push({
|
|
50
|
+
name: `LOWER(${column})`,
|
|
51
|
+
expression: {
|
|
52
|
+
__type: 'function',
|
|
53
|
+
name: 'LOWER',
|
|
54
|
+
args: [{ __type: 'column', column }],
|
|
55
|
+
},
|
|
56
|
+
order: opts?.order,
|
|
57
|
+
});
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Add UPPER(column) expression
|
|
62
|
+
*/
|
|
63
|
+
upper(column, opts) {
|
|
64
|
+
this.columns.push({
|
|
65
|
+
name: `UPPER(${column})`,
|
|
66
|
+
expression: {
|
|
67
|
+
__type: 'function',
|
|
68
|
+
name: 'UPPER',
|
|
69
|
+
args: [{ __type: 'column', column }],
|
|
70
|
+
},
|
|
71
|
+
order: opts?.order,
|
|
72
|
+
});
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Add LENGTH(column) expression
|
|
77
|
+
*/
|
|
78
|
+
length(column, opts) {
|
|
79
|
+
this.columns.push({
|
|
80
|
+
name: `LENGTH(${column})`,
|
|
81
|
+
expression: {
|
|
82
|
+
__type: 'function',
|
|
83
|
+
name: 'LENGTH',
|
|
84
|
+
args: [{ __type: 'column', column }],
|
|
85
|
+
},
|
|
86
|
+
order: opts?.order,
|
|
87
|
+
});
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Add SUBSTRING(column FROM start FOR length) expression
|
|
92
|
+
*/
|
|
93
|
+
substring(column, start, length, opts) {
|
|
94
|
+
const args = [
|
|
95
|
+
{ __type: 'column', column },
|
|
96
|
+
{ __type: 'literal', value: start, type: 'number' },
|
|
97
|
+
];
|
|
98
|
+
if (length) {
|
|
99
|
+
args.push({ __type: 'literal', value: length, type: 'number' });
|
|
100
|
+
}
|
|
101
|
+
this.columns.push({
|
|
102
|
+
name: `SUBSTRING(${column} FROM ${start}${length ? ' FOR ' + length : ''})`,
|
|
103
|
+
expression: {
|
|
104
|
+
__type: 'function',
|
|
105
|
+
name: 'SUBSTRING',
|
|
106
|
+
args,
|
|
107
|
+
},
|
|
108
|
+
order: opts?.order,
|
|
109
|
+
});
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Add a custom function expression
|
|
114
|
+
*/
|
|
115
|
+
fn(name, args, alias) {
|
|
116
|
+
const exprString = args.map(arg => {
|
|
117
|
+
if (typeof arg === 'string')
|
|
118
|
+
return arg;
|
|
119
|
+
if (arg.__type === 'column')
|
|
120
|
+
return arg.column;
|
|
121
|
+
if (arg.__type === 'literal')
|
|
122
|
+
return String(arg.value);
|
|
123
|
+
return '';
|
|
124
|
+
}).join(', ');
|
|
125
|
+
this.columns.push({
|
|
126
|
+
name: alias || `${name}(${exprString})`,
|
|
127
|
+
expression: {
|
|
128
|
+
__type: 'function',
|
|
129
|
+
name,
|
|
130
|
+
args,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Add COALESCE expression for handling NULLs
|
|
137
|
+
*/
|
|
138
|
+
coalesce(column, defaultValue) {
|
|
139
|
+
this.columns.push({
|
|
140
|
+
name: `COALESCE(${column}, ${defaultValue})`,
|
|
141
|
+
expression: {
|
|
142
|
+
__type: 'function',
|
|
143
|
+
name: 'COALESCE',
|
|
144
|
+
args: [
|
|
145
|
+
{ __type: 'column', column },
|
|
146
|
+
{ __type: 'literal', value: defaultValue },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Add CAST expression
|
|
154
|
+
*/
|
|
155
|
+
cast(column, asType) {
|
|
156
|
+
this.columns.push({
|
|
157
|
+
name: `CAST(${column} AS ${asType})`,
|
|
158
|
+
expression: {
|
|
159
|
+
__type: 'function',
|
|
160
|
+
name: 'CAST',
|
|
161
|
+
args: [
|
|
162
|
+
{ __type: 'column', column },
|
|
163
|
+
{ __type: 'literal', value: asType, type: 'string' },
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Add JSON extract expression (PostgreSQL)
|
|
171
|
+
*/
|
|
172
|
+
jsonExtract(column, path) {
|
|
173
|
+
this.columns.push({
|
|
174
|
+
name: `${column}->>'${path}'`,
|
|
175
|
+
expression: {
|
|
176
|
+
__type: 'function',
|
|
177
|
+
name: 'JSON_EXTRACT',
|
|
178
|
+
args: [
|
|
179
|
+
{ __type: 'column', column },
|
|
180
|
+
{ __type: 'literal', value: path, type: 'string' },
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get all index columns
|
|
188
|
+
*/
|
|
189
|
+
getColumns() {
|
|
190
|
+
return this.columns;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Build the index column expressions
|
|
194
|
+
*/
|
|
195
|
+
toSQL(dialect) {
|
|
196
|
+
return this.columns.map(col => {
|
|
197
|
+
let expr = col.name;
|
|
198
|
+
if (col.expression) {
|
|
199
|
+
if (col.expression.__type === 'function') {
|
|
200
|
+
const fn = col.expression;
|
|
201
|
+
const args = fn.args.map(arg => {
|
|
202
|
+
if (typeof arg === 'string')
|
|
203
|
+
return arg;
|
|
204
|
+
if (arg.__type === 'column')
|
|
205
|
+
return dialect.escapeId(arg.column);
|
|
206
|
+
if (arg.__type === 'literal')
|
|
207
|
+
return dialect.escape(arg.value);
|
|
208
|
+
return '';
|
|
209
|
+
}).join(', ');
|
|
210
|
+
expr = `${fn.name}(${args})`;
|
|
211
|
+
}
|
|
212
|
+
else if (col.expression.__type === 'column') {
|
|
213
|
+
expr = dialect.escapeId(col.expression.column);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
expr = dialect.escapeId(col.name);
|
|
218
|
+
}
|
|
219
|
+
if (col.length) {
|
|
220
|
+
expr += ` (${col.length})`;
|
|
221
|
+
}
|
|
222
|
+
if (col.order) {
|
|
223
|
+
expr += ` ${col.order}`;
|
|
224
|
+
}
|
|
225
|
+
return expr;
|
|
226
|
+
}).join(', ');
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Reset the builder
|
|
230
|
+
*/
|
|
231
|
+
reset() {
|
|
232
|
+
this.columns = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.IndexExpressionBuilder = IndexExpressionBuilder;
|
|
236
|
+
/**
|
|
237
|
+
* Create a new index expression builder
|
|
238
|
+
*/
|
|
239
|
+
function createIndexBuilder() {
|
|
240
|
+
return new IndexExpressionBuilder();
|
|
241
|
+
}
|
|
242
|
+
exports.default = { IndexExpressionBuilder, createIndexBuilder };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query Builders
|
|
4
|
+
* Exports all query builder classes and utilities
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SqlCompilerDefault = exports.buildUpdateWithOperations = exports.buildUpdateQuery = exports.createUpdateBuilder = exports.UpdateBuilder = exports.buildBulkInsertQuery = exports.buildInsertQuery = exports.createInsertBuilder = exports.InsertBuilder = exports.buildLimitOffset = exports.buildOrder = exports.createOrderLimitBuilder = exports.createOrderBuilder = exports.OrderLimitBuilder = exports.LimitOffsetBuilder = exports.OrderBuilder = exports.buildIncludes = exports.createIncludeBuilder = exports.IncludeBuilder = exports.buildWhereClause = exports.createWhereBuilder = exports.WhereBuilder = exports.createIndexBuilder = exports.IndexExpressionBuilder = exports.createViewBuilder = exports.ViewBuilder = exports.SubqueryBuilder = exports.createCTEBuilder = exports.CTEBuilder = exports.SqlCompiler = exports.isModel = exports.getModelName = exports.getTableName = void 0;
|
|
8
|
+
exports.createQueryBuilder = createQueryBuilder;
|
|
9
|
+
exports.createQuickQuery = createQuickQuery;
|
|
10
|
+
exports.getDefaultQueryBuilder = getDefaultQueryBuilder;
|
|
11
|
+
exports.setDefaultQueryBuilder = setDefaultQueryBuilder;
|
|
12
|
+
// Export model helpers
|
|
13
|
+
var model_helpers_1 = require("./model-helpers");
|
|
14
|
+
Object.defineProperty(exports, "getTableName", { enumerable: true, get: function () { return model_helpers_1.getTableName; } });
|
|
15
|
+
Object.defineProperty(exports, "getModelName", { enumerable: true, get: function () { return model_helpers_1.getModelName; } });
|
|
16
|
+
Object.defineProperty(exports, "isModel", { enumerable: true, get: function () { return model_helpers_1.isModel; } });
|
|
17
|
+
// Export SQL compiler
|
|
18
|
+
var sql_compiler_1 = require("./sql-compiler");
|
|
19
|
+
Object.defineProperty(exports, "SqlCompiler", { enumerable: true, get: function () { return sql_compiler_1.SqlCompiler; } });
|
|
20
|
+
// Export CTE builder
|
|
21
|
+
var cte_builder_1 = require("./cte-builder");
|
|
22
|
+
Object.defineProperty(exports, "CTEBuilder", { enumerable: true, get: function () { return cte_builder_1.CTEBuilder; } });
|
|
23
|
+
Object.defineProperty(exports, "createCTEBuilder", { enumerable: true, get: function () { return cte_builder_1.createCTEBuilder; } });
|
|
24
|
+
// Export subquery builder
|
|
25
|
+
var subquery_builder_1 = require("./subquery-builder");
|
|
26
|
+
Object.defineProperty(exports, "SubqueryBuilder", { enumerable: true, get: function () { return subquery_builder_1.SubqueryBuilder; } });
|
|
27
|
+
// Export view builder
|
|
28
|
+
var view_builder_1 = require("./view-builder");
|
|
29
|
+
Object.defineProperty(exports, "ViewBuilder", { enumerable: true, get: function () { return view_builder_1.ViewBuilder; } });
|
|
30
|
+
Object.defineProperty(exports, "createViewBuilder", { enumerable: true, get: function () { return view_builder_1.createViewBuilder; } });
|
|
31
|
+
// Export index expression builder
|
|
32
|
+
var index_expression_builder_1 = require("./index-expression-builder");
|
|
33
|
+
Object.defineProperty(exports, "IndexExpressionBuilder", { enumerable: true, get: function () { return index_expression_builder_1.IndexExpressionBuilder; } });
|
|
34
|
+
Object.defineProperty(exports, "createIndexBuilder", { enumerable: true, get: function () { return index_expression_builder_1.createIndexBuilder; } });
|
|
35
|
+
// Export modular query builders
|
|
36
|
+
var where_builder_1 = require("./where-builder");
|
|
37
|
+
Object.defineProperty(exports, "WhereBuilder", { enumerable: true, get: function () { return where_builder_1.WhereBuilder; } });
|
|
38
|
+
Object.defineProperty(exports, "createWhereBuilder", { enumerable: true, get: function () { return where_builder_1.createWhereBuilder; } });
|
|
39
|
+
Object.defineProperty(exports, "buildWhereClause", { enumerable: true, get: function () { return where_builder_1.buildWhereClause; } });
|
|
40
|
+
var include_builder_1 = require("./include-builder");
|
|
41
|
+
Object.defineProperty(exports, "IncludeBuilder", { enumerable: true, get: function () { return include_builder_1.IncludeBuilder; } });
|
|
42
|
+
Object.defineProperty(exports, "createIncludeBuilder", { enumerable: true, get: function () { return include_builder_1.createIncludeBuilder; } });
|
|
43
|
+
Object.defineProperty(exports, "buildIncludes", { enumerable: true, get: function () { return include_builder_1.buildIncludes; } });
|
|
44
|
+
var order_limit_builder_1 = require("./order-limit-builder");
|
|
45
|
+
Object.defineProperty(exports, "OrderBuilder", { enumerable: true, get: function () { return order_limit_builder_1.OrderBuilder; } });
|
|
46
|
+
Object.defineProperty(exports, "LimitOffsetBuilder", { enumerable: true, get: function () { return order_limit_builder_1.LimitOffsetBuilder; } });
|
|
47
|
+
Object.defineProperty(exports, "OrderLimitBuilder", { enumerable: true, get: function () { return order_limit_builder_1.OrderLimitBuilder; } });
|
|
48
|
+
Object.defineProperty(exports, "createOrderBuilder", { enumerable: true, get: function () { return order_limit_builder_1.createOrderBuilder; } });
|
|
49
|
+
Object.defineProperty(exports, "createOrderLimitBuilder", { enumerable: true, get: function () { return order_limit_builder_1.createOrderLimitBuilder; } });
|
|
50
|
+
Object.defineProperty(exports, "buildOrder", { enumerable: true, get: function () { return order_limit_builder_1.buildOrder; } });
|
|
51
|
+
Object.defineProperty(exports, "buildLimitOffset", { enumerable: true, get: function () { return order_limit_builder_1.buildLimitOffset; } });
|
|
52
|
+
var insert_builder_1 = require("./insert-builder");
|
|
53
|
+
Object.defineProperty(exports, "InsertBuilder", { enumerable: true, get: function () { return insert_builder_1.InsertBuilder; } });
|
|
54
|
+
Object.defineProperty(exports, "createInsertBuilder", { enumerable: true, get: function () { return insert_builder_1.createInsertBuilder; } });
|
|
55
|
+
Object.defineProperty(exports, "buildInsertQuery", { enumerable: true, get: function () { return insert_builder_1.buildInsertQuery; } });
|
|
56
|
+
Object.defineProperty(exports, "buildBulkInsertQuery", { enumerable: true, get: function () { return insert_builder_1.buildBulkInsertQuery; } });
|
|
57
|
+
var update_builder_1 = require("./update-builder");
|
|
58
|
+
Object.defineProperty(exports, "UpdateBuilder", { enumerable: true, get: function () { return update_builder_1.UpdateBuilder; } });
|
|
59
|
+
Object.defineProperty(exports, "createUpdateBuilder", { enumerable: true, get: function () { return update_builder_1.createUpdateBuilder; } });
|
|
60
|
+
Object.defineProperty(exports, "buildUpdateQuery", { enumerable: true, get: function () { return update_builder_1.buildUpdateQuery; } });
|
|
61
|
+
Object.defineProperty(exports, "buildUpdateWithOperations", { enumerable: true, get: function () { return update_builder_1.buildUpdateWithOperations; } });
|
|
62
|
+
/**
|
|
63
|
+
* Create a query builder with the given options
|
|
64
|
+
*/
|
|
65
|
+
function createQueryBuilder(options) {
|
|
66
|
+
// Import dynamically to avoid circular dependencies
|
|
67
|
+
const { SqlCompiler } = require('./sql-compiler');
|
|
68
|
+
const sqlCompiler = new SqlCompiler(undefined, {
|
|
69
|
+
parameterized: options?.parameterized,
|
|
70
|
+
paramChar: options?.paramChar,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
sqlCompiler,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Quick query helper for simple queries
|
|
78
|
+
*/
|
|
79
|
+
function createQuickQuery(dialect) {
|
|
80
|
+
const { SqlCompiler } = require('./sql-compiler');
|
|
81
|
+
const compiler = new SqlCompiler();
|
|
82
|
+
return {
|
|
83
|
+
/**
|
|
84
|
+
* Build a simple SELECT query
|
|
85
|
+
*/
|
|
86
|
+
select: (table, where) => {
|
|
87
|
+
return compiler.compileSelect({
|
|
88
|
+
tableName: table,
|
|
89
|
+
where,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Build a simple INSERT query
|
|
94
|
+
*/
|
|
95
|
+
insert: (table, values) => {
|
|
96
|
+
return compiler.compileInsert({
|
|
97
|
+
tableName: table,
|
|
98
|
+
values,
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Build a simple UPDATE query
|
|
103
|
+
*/
|
|
104
|
+
update: (table, values, where) => {
|
|
105
|
+
return compiler.compileUpdate({
|
|
106
|
+
tableName: table,
|
|
107
|
+
values,
|
|
108
|
+
where,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Build a simple DELETE query
|
|
113
|
+
*/
|
|
114
|
+
delete: (table, where) => {
|
|
115
|
+
return compiler.compileDelete({
|
|
116
|
+
tableName: table,
|
|
117
|
+
where,
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Build a WHERE clause
|
|
122
|
+
*/
|
|
123
|
+
where: (conditions) => {
|
|
124
|
+
return compiler.compileWhere(conditions);
|
|
125
|
+
},
|
|
126
|
+
/**
|
|
127
|
+
* Build an ORDER BY clause
|
|
128
|
+
*/
|
|
129
|
+
order: (order) => {
|
|
130
|
+
return compiler.compileOrder(order);
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Build a LIMIT/OFFSET clause
|
|
134
|
+
*/
|
|
135
|
+
limitOffset: (limit, offset) => {
|
|
136
|
+
return compiler.compileLimitOffset(limit, offset);
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Default query builder instance
|
|
142
|
+
*/
|
|
143
|
+
let defaultQueryBuilder = null;
|
|
144
|
+
/**
|
|
145
|
+
* Get or create the default query builder
|
|
146
|
+
*/
|
|
147
|
+
function getDefaultQueryBuilder() {
|
|
148
|
+
if (!defaultQueryBuilder) {
|
|
149
|
+
defaultQueryBuilder = createQuickQuery();
|
|
150
|
+
}
|
|
151
|
+
return defaultQueryBuilder;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Set the default query builder
|
|
155
|
+
*/
|
|
156
|
+
function setDefaultQueryBuilder(builder) {
|
|
157
|
+
defaultQueryBuilder = builder;
|
|
158
|
+
}
|
|
159
|
+
// Re-export for default export
|
|
160
|
+
var sql_compiler_2 = require("./sql-compiler");
|
|
161
|
+
Object.defineProperty(exports, "SqlCompilerDefault", { enumerable: true, get: function () { return sql_compiler_2.SqlCompiler; } });
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Insert query builder for the ORM
|
|
4
|
+
* Handles INSERT queries including bulk inserts and upserts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.InsertBuilder = void 0;
|
|
8
|
+
exports.createInsertBuilder = createInsertBuilder;
|
|
9
|
+
exports.buildInsertQuery = buildInsertQuery;
|
|
10
|
+
exports.buildBulkInsertQuery = buildBulkInsertQuery;
|
|
11
|
+
/**
|
|
12
|
+
* InsertBuilder class for building INSERT queries
|
|
13
|
+
*/
|
|
14
|
+
class InsertBuilder {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build an INSERT query for a single record
|
|
20
|
+
*/
|
|
21
|
+
build(tableName, values) {
|
|
22
|
+
const queryValues = [];
|
|
23
|
+
const columns = Object.keys(values);
|
|
24
|
+
if (columns.length === 0) {
|
|
25
|
+
return {
|
|
26
|
+
sql: `INSERT INTO ${this.escapeId(tableName)} DEFAULT VALUES`,
|
|
27
|
+
values: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const placeholders = columns.map(() => '?').join(', ');
|
|
31
|
+
const columnSql = columns.map((c) => this.escapeId(c)).join(', ');
|
|
32
|
+
let sql = `INSERT INTO ${this.escapeId(tableName)} (${columnSql}) VALUES (${placeholders})`;
|
|
33
|
+
// Add query values
|
|
34
|
+
queryValues.push(...Object.values(values));
|
|
35
|
+
// Handle upsert (ON CONFLICT)
|
|
36
|
+
if (this.options.upsert) {
|
|
37
|
+
sql = this.buildUpsert(sql, columns, values);
|
|
38
|
+
}
|
|
39
|
+
// Handle RETURNING clause
|
|
40
|
+
if (this.options.returning) {
|
|
41
|
+
sql += this.buildReturningClause();
|
|
42
|
+
}
|
|
43
|
+
return { sql, values: queryValues };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a bulk INSERT query
|
|
47
|
+
*/
|
|
48
|
+
buildBulk(tableName, records) {
|
|
49
|
+
if (records.length === 0) {
|
|
50
|
+
return { sql: '', values: [] };
|
|
51
|
+
}
|
|
52
|
+
// Get all unique columns from all records
|
|
53
|
+
const columnSet = new Set();
|
|
54
|
+
for (const record of records) {
|
|
55
|
+
Object.keys(record).forEach((key) => columnSet.add(key));
|
|
56
|
+
}
|
|
57
|
+
const columns = Array.from(columnSet);
|
|
58
|
+
const columnSql = columns.map((c) => this.escapeId(c)).join(', ');
|
|
59
|
+
// Build values for each record
|
|
60
|
+
const values = [];
|
|
61
|
+
const valueTuples = [];
|
|
62
|
+
for (const record of records) {
|
|
63
|
+
const placeholders = columns
|
|
64
|
+
.map((col) => {
|
|
65
|
+
const value = record[col];
|
|
66
|
+
values.push(value);
|
|
67
|
+
return '?';
|
|
68
|
+
})
|
|
69
|
+
.join(', ');
|
|
70
|
+
valueTuples.push(`(${placeholders})`);
|
|
71
|
+
}
|
|
72
|
+
let sql = `INSERT INTO ${this.escapeId(tableName)} (${columnSql}) VALUES ${valueTuples.join(', ')}`;
|
|
73
|
+
// Handle bulk upsert
|
|
74
|
+
if (this.options.upsert) {
|
|
75
|
+
sql = this.buildBulkUpsert(sql, columns);
|
|
76
|
+
}
|
|
77
|
+
// Handle RETURNING clause
|
|
78
|
+
if (this.options.returning) {
|
|
79
|
+
sql += this.buildReturningClause();
|
|
80
|
+
}
|
|
81
|
+
return { sql, values };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Build an upsert (INSERT ... ON CONFLICT) query
|
|
85
|
+
*/
|
|
86
|
+
buildUpsert(baseSql, columns, values) {
|
|
87
|
+
const conflictFields = this.options.conflictFields || columns;
|
|
88
|
+
// Build the ON CONFLICT clause
|
|
89
|
+
const conflictColumns = conflictFields.map((c) => this.escapeId(c)).join(', ');
|
|
90
|
+
// Build the DO UPDATE SET clause
|
|
91
|
+
const updateSet = columns
|
|
92
|
+
.filter((col) => !conflictFields.includes(col) || values[col] !== undefined)
|
|
93
|
+
.map((col) => `${this.escapeId(col)} = excluded.${this.escapeId(col)}`)
|
|
94
|
+
.join(', ');
|
|
95
|
+
if (updateSet) {
|
|
96
|
+
return `${baseSql} ON CONFLICT (${conflictColumns}) DO UPDATE SET ${updateSet}`;
|
|
97
|
+
}
|
|
98
|
+
// If no columns to update, do nothing (just ignore conflict)
|
|
99
|
+
return `${baseSql} ON CONFLICT (${conflictColumns}) DO NOTHING`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build a bulk upsert query
|
|
103
|
+
*/
|
|
104
|
+
buildBulkUpsert(baseSql, columns) {
|
|
105
|
+
const conflictFields = this.options.conflictFields || columns;
|
|
106
|
+
const conflictColumns = conflictFields.map((c) => this.escapeId(c)).join(', ');
|
|
107
|
+
const updateSet = columns
|
|
108
|
+
.filter((col) => !conflictFields.includes(col))
|
|
109
|
+
.map((col) => `${this.escapeId(col)} = excluded.${this.escapeId(col)}`)
|
|
110
|
+
.join(', ');
|
|
111
|
+
if (updateSet) {
|
|
112
|
+
return `${baseSql} ON CONFLICT (${conflictColumns}) DO UPDATE SET ${updateSet}`;
|
|
113
|
+
}
|
|
114
|
+
return `${baseSql} ON CONFLICT (${conflictColumns}) DO NOTHING`;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Build the RETURNING clause
|
|
118
|
+
*/
|
|
119
|
+
buildReturningClause() {
|
|
120
|
+
if (!this.options.returning) {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
if (this.options.returning === true) {
|
|
124
|
+
return ' RETURNING *';
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(this.options.returning)) {
|
|
127
|
+
const cols = this.options.returning.map((c) => this.escapeId(c)).join(', ');
|
|
128
|
+
return ` RETURNING ${cols}`;
|
|
129
|
+
}
|
|
130
|
+
return '';
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Escape an identifier
|
|
134
|
+
*/
|
|
135
|
+
escapeId(identifier) {
|
|
136
|
+
const id = String(identifier ?? '');
|
|
137
|
+
if (this.options.dialect?.escapeId) {
|
|
138
|
+
return this.options.dialect.escapeId(id);
|
|
139
|
+
}
|
|
140
|
+
return `"${id.replace(/"/g, '""')}"`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.InsertBuilder = InsertBuilder;
|
|
144
|
+
/**
|
|
145
|
+
* Create an InsertBuilder instance
|
|
146
|
+
*/
|
|
147
|
+
function createInsertBuilder(options) {
|
|
148
|
+
return new InsertBuilder(options);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Quick helper to build an INSERT query
|
|
152
|
+
*/
|
|
153
|
+
function buildInsertQuery(tableName, values, options) {
|
|
154
|
+
const builder = new InsertBuilder(options);
|
|
155
|
+
return builder.build(tableName, values);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Quick helper to build a bulk INSERT query
|
|
159
|
+
*/
|
|
160
|
+
function buildBulkInsertQuery(tableName, records, options) {
|
|
161
|
+
const builder = new InsertBuilder(options);
|
|
162
|
+
return builder.buildBulk(tableName, records);
|
|
163
|
+
}
|
|
164
|
+
exports.default = InsertBuilder;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Model Helpers
|
|
4
|
+
* Utilities for working with Model classes in builders
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getTableName = getTableName;
|
|
8
|
+
exports.isModel = isModel;
|
|
9
|
+
exports.getModelName = getModelName;
|
|
10
|
+
/**
|
|
11
|
+
* Get table name from a model class or string
|
|
12
|
+
*/
|
|
13
|
+
function getTableName(model) {
|
|
14
|
+
if (typeof model === 'string') {
|
|
15
|
+
return model;
|
|
16
|
+
}
|
|
17
|
+
return model.tableName || model.name || '';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if value is a model class (has tableName or name property)
|
|
21
|
+
*/
|
|
22
|
+
function isModel(value) {
|
|
23
|
+
if (!value || typeof value === 'string') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const anyVal = value;
|
|
27
|
+
return !!(anyVal.tableName || anyVal.name);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get model name from model class
|
|
31
|
+
*/
|
|
32
|
+
function getModelName(model) {
|
|
33
|
+
if (typeof model === 'string') {
|
|
34
|
+
return model;
|
|
35
|
+
}
|
|
36
|
+
return model.name || model.tableName || '';
|
|
37
|
+
}
|
|
38
|
+
exports.default = { getTableName, isModel, getModelName };
|