@ductape/sdk 0.0.4-v51 → 0.0.4-v52
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/README.md +1 -1
- package/dist/agents/agent-context.d.ts +98 -0
- package/dist/agents/agent-context.js +588 -0
- package/dist/agents/agent-context.js.map +1 -0
- package/dist/agents/agent-executor.d.ts +180 -0
- package/dist/agents/agent-executor.js +715 -0
- package/dist/agents/agent-executor.js.map +1 -0
- package/dist/agents/agents.service.d.ts +304 -0
- package/dist/agents/agents.service.js +1244 -0
- package/dist/agents/agents.service.js.map +1 -0
- package/dist/agents/index.d.ts +55 -0
- package/dist/agents/index.js +110 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/memory-manager.d.ts +182 -0
- package/dist/agents/memory-manager.js +383 -0
- package/dist/agents/memory-manager.js.map +1 -0
- package/dist/agents/tool-registry.d.ts +141 -0
- package/dist/agents/tool-registry.js +355 -0
- package/dist/agents/tool-registry.js.map +1 -0
- package/dist/agents/types/agents.types.d.ts +1225 -0
- package/dist/agents/types/agents.types.js +12 -0
- package/dist/agents/types/agents.types.js.map +1 -0
- package/dist/agents/types/index.d.ts +6 -0
- package/dist/agents/types/index.js +23 -0
- package/dist/agents/types/index.js.map +1 -0
- package/dist/agents/vector-store-adapter.d.ts +108 -0
- package/dist/agents/vector-store-adapter.js +213 -0
- package/dist/agents/vector-store-adapter.js.map +1 -0
- package/dist/api/services/appApi.service.js +4 -5
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/processorApi.service.d.ts +322 -0
- package/dist/api/services/processorApi.service.js +252 -0
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +69 -1
- package/dist/api/services/productsApi.service.js +67 -31
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/resilienceApi.service.d.ts +106 -0
- package/dist/api/services/resilienceApi.service.js +224 -0
- package/dist/api/services/resilienceApi.service.js.map +1 -0
- package/dist/api/services/secretsApi.service.d.ts +38 -0
- package/dist/api/services/secretsApi.service.js +96 -0
- package/dist/api/services/secretsApi.service.js.map +1 -0
- package/dist/api/services/userApi.service.js +0 -1
- package/dist/api/services/userApi.service.js.map +1 -1
- package/dist/api/services/workflowApi.service.d.ts +199 -0
- package/dist/api/services/workflowApi.service.js +183 -0
- package/dist/api/services/workflowApi.service.js.map +1 -0
- package/dist/api/services/workspaceApi.service.js +0 -1
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +57 -0
- package/dist/api/urls.js +68 -1
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/cache.utils.js +4 -10
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +0 -10
- package/dist/apps/services/app.service.js +74 -30
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/utils/auth-context-manager.d.ts +137 -0
- package/dist/apps/utils/auth-context-manager.js +248 -0
- package/dist/apps/utils/auth-context-manager.js.map +1 -0
- package/dist/apps/utils/credential-manager.d.ts +128 -0
- package/dist/apps/utils/credential-manager.js +199 -0
- package/dist/apps/utils/credential-manager.js.map +1 -0
- package/dist/apps/utils/index.d.ts +10 -0
- package/dist/apps/utils/index.js +54 -0
- package/dist/apps/utils/index.js.map +1 -0
- package/dist/apps/utils/input-helpers.d.ts +67 -0
- package/dist/apps/utils/input-helpers.js +185 -0
- package/dist/apps/utils/input-helpers.js.map +1 -0
- package/dist/apps/utils/input-resolver.d.ts +165 -0
- package/dist/apps/utils/input-resolver.js +477 -0
- package/dist/apps/utils/input-resolver.js.map +1 -0
- package/dist/apps/utils/oauth-manager.d.ts +196 -0
- package/dist/apps/utils/oauth-manager.js +405 -0
- package/dist/apps/utils/oauth-manager.js.map +1 -0
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +2 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +15 -2
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +2 -1
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +14 -2
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -1
- package/dist/bin.d.ts +26 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/brokers/brokers.service.d.ts +257 -0
- package/dist/brokers/brokers.service.js +604 -0
- package/dist/brokers/brokers.service.js.map +1 -0
- package/dist/brokers/index.d.ts +46 -0
- package/dist/brokers/index.js +83 -0
- package/dist/brokers/index.js.map +1 -0
- package/dist/brokers/types/index.d.ts +288 -0
- package/dist/brokers/types/index.js +8 -0
- package/dist/brokers/types/index.js.map +1 -0
- package/dist/brokers/utils/broker.util.d.ts +33 -0
- package/dist/brokers/utils/broker.util.js +125 -0
- package/dist/brokers/utils/broker.util.js.map +1 -0
- package/dist/brokers/utils/providers/aws-sqs.service.d.ts +16 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js +71 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js.map +1 -0
- package/dist/brokers/utils/providers/google-pubsub.service.d.ts +16 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js +43 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js.map +1 -0
- package/dist/brokers/utils/providers/index.d.ts +6 -0
- package/dist/brokers/utils/providers/index.js +16 -0
- package/dist/brokers/utils/providers/index.js.map +1 -0
- package/dist/brokers/utils/providers/kafka.service.d.ts +16 -0
- package/dist/brokers/utils/providers/kafka.service.js +52 -0
- package/dist/brokers/utils/providers/kafka.service.js.map +1 -0
- package/dist/brokers/utils/providers/nats.service.d.ts +18 -0
- package/dist/brokers/utils/providers/nats.service.js +63 -0
- package/dist/brokers/utils/providers/nats.service.js.map +1 -0
- package/dist/brokers/utils/providers/rabbitmq.service.d.ts +14 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js +67 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -0
- package/dist/brokers/utils/providers/redis.service.d.ts +18 -0
- package/dist/brokers/utils/providers/redis.service.js +93 -0
- package/dist/brokers/utils/providers/redis.service.js.map +1 -0
- package/dist/cache/cache.manager.d.ts +159 -0
- package/dist/cache/cache.manager.js +265 -0
- package/dist/cache/cache.manager.js.map +1 -0
- package/dist/cache/cache.service.d.ts +186 -0
- package/dist/cache/cache.service.js +437 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.js +79 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types/index.d.ts +106 -0
- package/dist/cache/types/index.js +6 -0
- package/dist/cache/types/index.js.map +1 -0
- package/dist/database/actions/action-manager.d.ts +170 -0
- package/dist/database/actions/action-manager.js +465 -0
- package/dist/database/actions/action-manager.js.map +1 -0
- package/dist/database/actions/index.d.ts +6 -0
- package/dist/database/actions/index.js +13 -0
- package/dist/database/actions/index.js.map +1 -0
- package/dist/database/adapters/adapter.factory.d.ts +62 -0
- package/dist/database/adapters/adapter.factory.js +97 -0
- package/dist/database/adapters/adapter.factory.js.map +1 -0
- package/dist/database/adapters/base.adapter.d.ts +307 -90
- package/dist/database/adapters/base.adapter.js +139 -20
- package/dist/database/adapters/base.adapter.js.map +1 -1
- package/dist/database/adapters/cassandra.adapter.d.ts +90 -0
- package/dist/database/adapters/cassandra.adapter.js +1019 -0
- package/dist/database/adapters/cassandra.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +94 -77
- package/dist/database/adapters/dynamodb.adapter.js +1162 -1305
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -1
- package/dist/database/adapters/index.d.ts +11 -0
- package/dist/database/adapters/index.js +27 -0
- package/dist/database/adapters/index.js.map +1 -0
- package/dist/database/adapters/mariadb.adapter.d.ts +100 -0
- package/dist/database/adapters/mariadb.adapter.js +247 -0
- package/dist/database/adapters/mariadb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +105 -57
- package/dist/database/adapters/mongodb.adapter.js +941 -838
- package/dist/database/adapters/mongodb.adapter.js.map +1 -1
- package/dist/database/adapters/mysql.adapter.d.ts +76 -138
- package/dist/database/adapters/mysql.adapter.js +990 -1246
- package/dist/database/adapters/mysql.adapter.js.map +1 -1
- package/dist/database/adapters/postgresql.adapter.d.ts +75 -139
- package/dist/database/adapters/postgresql.adapter.js +1076 -1346
- package/dist/database/adapters/postgresql.adapter.js.map +1 -1
- package/dist/database/databases.service.d.ts +1374 -0
- package/dist/database/databases.service.js +2680 -0
- package/dist/database/databases.service.js.map +1 -0
- package/dist/database/index.d.ts +41 -13
- package/dist/database/index.js +97 -86
- package/dist/database/index.js.map +1 -1
- package/dist/database/migrations/index.d.ts +6 -0
- package/dist/database/migrations/index.js +12 -0
- package/dist/database/migrations/index.js.map +1 -0
- package/dist/database/migrations/migration-engine.d.ts +132 -0
- package/dist/database/migrations/migration-engine.js +1356 -0
- package/dist/database/migrations/migration-engine.js.map +1 -0
- package/dist/database/operators/aggregation-builder.d.ts +64 -0
- package/dist/database/operators/aggregation-builder.js +746 -0
- package/dist/database/operators/aggregation-builder.js.map +1 -0
- package/dist/database/operators/index.d.ts +7 -0
- package/dist/database/operators/index.js +15 -0
- package/dist/database/operators/index.js.map +1 -0
- package/dist/database/operators/query-builder.d.ts +55 -0
- package/dist/database/operators/query-builder.js +365 -0
- package/dist/database/operators/query-builder.js.map +1 -0
- package/dist/database/presave/decrypt.d.ts +25 -0
- package/dist/database/presave/decrypt.js +146 -0
- package/dist/database/presave/decrypt.js.map +1 -0
- package/dist/database/presave/index.d.ts +9 -0
- package/dist/database/presave/index.js +18 -0
- package/dist/database/presave/index.js.map +1 -0
- package/dist/database/presave/presave-processor.d.ts +148 -0
- package/dist/database/presave/presave-processor.js +702 -0
- package/dist/database/presave/presave-processor.js.map +1 -0
- package/dist/database/schema/index.d.ts +7 -0
- package/dist/database/schema/index.js +13 -0
- package/dist/database/schema/index.js.map +1 -0
- package/dist/database/schema/schema-manager.d.ts +258 -0
- package/dist/database/schema/schema-manager.js +637 -0
- package/dist/database/schema/schema-manager.js.map +1 -0
- package/dist/database/transactions/index.d.ts +6 -0
- package/dist/database/transactions/index.js +13 -0
- package/dist/database/transactions/index.js.map +1 -0
- package/dist/database/transactions/transaction-manager.d.ts +113 -0
- package/dist/database/transactions/transaction-manager.js +344 -0
- package/dist/database/transactions/transaction-manager.js.map +1 -0
- package/dist/database/triggers/index.d.ts +7 -0
- package/dist/database/triggers/index.js +14 -0
- package/dist/database/triggers/index.js.map +1 -0
- package/dist/database/triggers/trigger-processor.d.ts +239 -0
- package/dist/database/triggers/trigger-processor.js +1034 -0
- package/dist/database/triggers/trigger-processor.js.map +1 -0
- package/dist/database/types/action.interface.d.ts +148 -0
- package/dist/database/types/action.interface.js +6 -0
- package/dist/database/types/action.interface.js.map +1 -0
- package/dist/database/types/aggregation.interface.d.ts +179 -0
- package/dist/database/types/aggregation.interface.js +6 -0
- package/dist/database/types/aggregation.interface.js.map +1 -0
- package/dist/database/types/connection.interface.d.ts +137 -0
- package/dist/database/types/connection.interface.js +6 -0
- package/dist/database/types/connection.interface.js.map +1 -0
- package/dist/database/types/enums.d.ts +195 -0
- package/dist/database/types/enums.js +244 -0
- package/dist/database/types/enums.js.map +1 -0
- package/dist/database/types/index.d.ts +12 -10
- package/dist/database/types/index.js +26 -32
- package/dist/database/types/index.js.map +1 -1
- package/dist/database/types/migration.interface.d.ts +686 -0
- package/dist/database/types/migration.interface.js +9 -0
- package/dist/database/types/migration.interface.js.map +1 -0
- package/dist/database/types/presave.interface.d.ts +292 -0
- package/dist/database/types/presave.interface.js +60 -0
- package/dist/database/types/presave.interface.js.map +1 -0
- package/dist/database/types/query.interface.d.ts +199 -0
- package/dist/database/types/query.interface.js +6 -0
- package/dist/database/types/query.interface.js.map +1 -0
- package/dist/database/types/schema.interface.d.ts +398 -0
- package/dist/database/types/schema.interface.js +6 -0
- package/dist/database/types/schema.interface.js.map +1 -0
- package/dist/database/types/transaction.interface.d.ts +84 -0
- package/dist/database/types/transaction.interface.js +6 -0
- package/dist/database/types/transaction.interface.js.map +1 -0
- package/dist/database/types/trigger.interface.d.ts +612 -0
- package/dist/database/types/trigger.interface.js +121 -0
- package/dist/database/types/trigger.interface.js.map +1 -0
- package/dist/database/types/write.interface.d.ts +208 -0
- package/dist/database/types/write.interface.js +6 -0
- package/dist/database/types/write.interface.js.map +1 -0
- package/dist/database/utils/database-error.d.ts +96 -0
- package/dist/database/utils/database-error.js +221 -0
- package/dist/database/utils/database-error.js.map +1 -0
- package/dist/database/utils/index.d.ts +6 -0
- package/dist/database/utils/index.js +11 -0
- package/dist/database/utils/index.js.map +1 -0
- package/dist/graph/adapters/adapter.factory.d.ts +47 -0
- package/dist/graph/adapters/adapter.factory.js +77 -0
- package/dist/graph/adapters/adapter.factory.js.map +1 -0
- package/dist/graph/adapters/arangodb.adapter.d.ts +78 -72
- package/dist/graph/adapters/arangodb.adapter.js +1310 -1220
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -1
- package/dist/graph/adapters/base.adapter.d.ts +135 -118
- package/dist/graph/adapters/base.adapter.js +46 -20
- package/dist/graph/adapters/base.adapter.js.map +1 -1
- package/dist/graph/adapters/index.d.ts +5 -4
- package/dist/graph/adapters/index.js +6 -8
- package/dist/graph/adapters/index.js.map +1 -1
- package/dist/graph/adapters/memgraph.adapter.d.ts +98 -73
- package/dist/graph/adapters/memgraph.adapter.js +1050 -1202
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -1
- package/dist/graph/adapters/neo4j.adapter.d.ts +71 -78
- package/dist/graph/adapters/neo4j.adapter.js +912 -1605
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -1
- package/dist/graph/adapters/neptune.adapter.d.ts +76 -81
- package/dist/graph/adapters/neptune.adapter.js +1095 -1228
- package/dist/graph/adapters/neptune.adapter.js.map +1 -1
- package/dist/graph/graphs.service.d.ts +524 -0
- package/dist/graph/graphs.service.js +1683 -0
- package/dist/graph/graphs.service.js.map +1 -0
- package/dist/graph/index.d.ts +54 -8
- package/dist/graph/index.js +67 -32
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/transactions/index.d.ts +4 -0
- package/dist/graph/transactions/index.js +9 -0
- package/dist/graph/transactions/index.js.map +1 -0
- package/dist/graph/transactions/transaction-manager.d.ts +61 -0
- package/dist/graph/transactions/transaction-manager.js +126 -0
- package/dist/graph/transactions/transaction-manager.js.map +1 -0
- package/dist/graph/types/connection.interface.d.ts +141 -0
- package/dist/graph/types/connection.interface.js +9 -0
- package/dist/graph/types/connection.interface.js.map +1 -0
- package/dist/graph/types/enums.d.ts +101 -0
- package/dist/graph/types/enums.js +114 -0
- package/dist/graph/types/enums.js.map +1 -0
- package/dist/graph/types/index.d.ts +11 -9
- package/dist/graph/types/index.js +15 -30
- package/dist/graph/types/index.js.map +1 -1
- package/dist/graph/types/node.interface.d.ts +248 -0
- package/dist/graph/types/node.interface.js +9 -0
- package/dist/graph/types/node.interface.js.map +1 -0
- package/dist/graph/types/query.interface.d.ts +168 -0
- package/dist/graph/types/query.interface.js +9 -0
- package/dist/graph/types/query.interface.js.map +1 -0
- package/dist/graph/types/relationship.interface.d.ts +207 -0
- package/dist/graph/types/relationship.interface.js +9 -0
- package/dist/graph/types/relationship.interface.js.map +1 -0
- package/dist/graph/types/schema.interface.d.ts +295 -0
- package/dist/graph/types/schema.interface.js +9 -0
- package/dist/graph/types/schema.interface.js.map +1 -0
- package/dist/graph/types/transaction.interface.d.ts +55 -0
- package/dist/graph/types/transaction.interface.js +9 -0
- package/dist/graph/types/transaction.interface.js.map +1 -0
- package/dist/graph/types/traversal.interface.d.ts +181 -0
- package/dist/graph/types/traversal.interface.js +9 -0
- package/dist/graph/types/traversal.interface.js.map +1 -0
- package/dist/graph/utils/graph-error.d.ts +71 -0
- package/dist/graph/utils/graph-error.js +142 -0
- package/dist/graph/utils/graph-error.js.map +1 -0
- package/dist/graph/utils/index.d.ts +4 -0
- package/dist/graph/utils/index.js +9 -0
- package/dist/graph/utils/index.js.map +1 -0
- package/dist/index.d.ts +1905 -875
- package/dist/index.js +3063 -1282
- package/dist/index.js.map +1 -1
- package/dist/init.interface.d.ts +407 -0
- package/dist/init.interface.js +3 -0
- package/dist/init.interface.js.map +1 -0
- package/dist/jobs/index.d.ts +38 -0
- package/dist/jobs/index.js +50 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/jobs.service.d.ts +154 -0
- package/dist/jobs/jobs.service.js +491 -0
- package/dist/jobs/jobs.service.js.map +1 -0
- package/dist/jobs/jobs.state.d.ts +113 -0
- package/dist/jobs/jobs.state.js +447 -0
- package/dist/jobs/jobs.state.js.map +1 -0
- package/dist/jobs/types.d.ts +449 -0
- package/dist/jobs/types.js +74 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/logs/logs.types.d.ts +12 -2
- package/dist/logs/logs.types.js +5 -1
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +11 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/models.service.d.ts +137 -0
- package/dist/models/models.service.js +195 -0
- package/dist/models/models.service.js.map +1 -0
- package/dist/notifications/index.d.ts +13 -0
- package/dist/notifications/index.js +26 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/notifications.service.d.ts +252 -0
- package/dist/notifications/notifications.service.js +654 -0
- package/dist/notifications/notifications.service.js.map +1 -0
- package/dist/notifications/types/index.d.ts +4 -0
- package/dist/notifications/types/index.js +21 -0
- package/dist/notifications/types/index.js.map +1 -0
- package/dist/notifications/types/notifications.types.d.ts +400 -0
- package/dist/notifications/types/notifications.types.js +49 -0
- package/dist/notifications/types/notifications.types.js.map +1 -0
- package/dist/processor/services/messagebrokers/kafka.service.js +2 -0
- package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +1 -9
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +11 -40
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +86 -70
- package/dist/processor/services/processor.service.js +1353 -1259
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/utils/processor.utils.js +5 -1
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/products/services/products.service.d.ts +167 -25
- package/dist/products/services/products.service.js +1248 -412
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/validators/index.d.ts +6 -3
- package/dist/products/validators/index.js +14 -5
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productAgent.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js +218 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +4 -15
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +109 -501
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productGraph.validator.js +14 -9
- package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +0 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +87 -30
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productModel.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js +132 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +135 -50
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productStorage.validator.js +77 -18
- package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productVector.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js +135 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/update.productDatabase.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +0 -6
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +26 -28
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productGraph.validator.js +11 -12
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +0 -1
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/resilience/fallback.service.d.ts +88 -0
- package/dist/resilience/fallback.service.js +511 -0
- package/dist/resilience/fallback.service.js.map +1 -0
- package/dist/resilience/healthcheck.service.d.ts +106 -0
- package/dist/resilience/healthcheck.service.js +379 -0
- package/dist/resilience/healthcheck.service.js.map +1 -0
- package/dist/resilience/index.d.ts +104 -0
- package/dist/resilience/index.js +140 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/resilience/quota.service.d.ts +90 -0
- package/dist/resilience/quota.service.js +519 -0
- package/dist/resilience/quota.service.js.map +1 -0
- package/dist/resilience/resilience.service.d.ts +95 -0
- package/dist/resilience/resilience.service.js +525 -0
- package/dist/resilience/resilience.service.js.map +1 -0
- package/dist/resilience/types/index.d.ts +479 -0
- package/dist/resilience/types/index.js +26 -0
- package/dist/resilience/types/index.js.map +1 -0
- package/dist/secrets/index.d.ts +10 -0
- package/dist/secrets/index.js +33 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/secrets.resolver.d.ts +52 -0
- package/dist/secrets/secrets.resolver.js +233 -0
- package/dist/secrets/secrets.resolver.js.map +1 -0
- package/dist/secrets/secrets.service.d.ts +83 -0
- package/dist/secrets/secrets.service.js +159 -0
- package/dist/secrets/secrets.service.js.map +1 -0
- package/dist/secrets/secrets.types.d.ts +188 -0
- package/dist/secrets/secrets.types.js +87 -0
- package/dist/secrets/secrets.types.js.map +1 -0
- package/dist/sessions/index.d.ts +50 -0
- package/dist/sessions/index.js +93 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/sessions.helper.d.ts +68 -0
- package/dist/sessions/sessions.helper.js +116 -0
- package/dist/sessions/sessions.helper.js.map +1 -0
- package/dist/sessions/sessions.resolver.d.ts +150 -0
- package/dist/sessions/sessions.resolver.js +356 -0
- package/dist/sessions/sessions.resolver.js.map +1 -0
- package/dist/sessions/sessions.service.d.ts +170 -0
- package/dist/sessions/sessions.service.js +736 -0
- package/dist/sessions/sessions.service.js.map +1 -0
- package/dist/sessions/types/index.d.ts +290 -0
- package/dist/sessions/types/index.js +6 -0
- package/dist/sessions/types/index.js.map +1 -0
- package/dist/storage/index.d.ts +66 -0
- package/dist/storage/index.js +98 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.service.d.ts +123 -0
- package/dist/storage/storage.service.js +478 -0
- package/dist/storage/storage.service.js.map +1 -0
- package/dist/storage/types/index.d.ts +207 -0
- package/dist/storage/types/index.js +6 -0
- package/dist/storage/types/index.js.map +1 -0
- package/dist/storage/utils/storage.util.d.ts +51 -0
- package/dist/storage/utils/storage.util.js +402 -0
- package/dist/storage/utils/storage.util.js.map +1 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.js +13 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/test.appBuilder.d.ts +0 -1
- package/dist/test/test.appBuilder.js +0 -15
- package/dist/test/test.appBuilder.js.map +1 -1
- package/dist/test/test.database.js +140 -0
- package/dist/test/test.database.js.map +1 -0
- package/dist/test/test.health.d.ts +0 -1
- package/dist/test/test.health.js +0 -48
- package/dist/test/test.health.js.map +1 -1
- package/dist/test/test.import.d.ts +0 -1
- package/dist/test/test.import.js +0 -1506
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.import.openapi.d.ts +0 -1
- package/dist/test/test.import.openapi.js +0 -75
- package/dist/test/test.import.openapi.js.map +1 -1
- package/dist/test/test.imports.d.ts +0 -1
- package/dist/test/test.imports.js +0 -76
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.logs.d.ts +0 -1
- package/dist/test/test.logs.js +0 -17
- package/dist/test/test.logs.js.map +1 -1
- package/dist/test/test.notifiers.d.ts +0 -1
- package/dist/test/test.notifiers.js +0 -84
- package/dist/test/test.notifiers.js.map +1 -1
- package/dist/test/test.processor.d.ts +0 -1
- package/dist/test/test.processor.js +0 -37
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.productBuilder.d.ts +0 -1
- package/dist/test/test.productBuilder.js +0 -660
- package/dist/test/test.productBuilder.js.map +1 -1
- package/dist/test/test.products.d.ts +0 -1
- package/dist/test/test.products.js +0 -48
- package/dist/test/test.products.js.map +1 -1
- package/dist/test/test.storage.js +332 -0
- package/dist/test/test.storage.js.map +1 -0
- package/dist/test/test.triggers.js +314 -0
- package/dist/test/test.triggers.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +1 -1
- package/dist/types/enums.d.ts +6 -1
- package/dist/types/enums.js +5 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/processor.types.d.ts +197 -35
- package/dist/types/processor.types.js +9 -1
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +837 -75
- package/dist/types/productsBuilder.types.js +168 -62
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +2 -49
- package/dist/utils/index.js.map +1 -1
- package/dist/vector/adapters/base.adapter.d.ts +152 -0
- package/dist/vector/adapters/base.adapter.js +137 -0
- package/dist/vector/adapters/base.adapter.js.map +1 -0
- package/dist/vector/adapters/index.d.ts +10 -0
- package/dist/vector/adapters/index.js +19 -0
- package/dist/vector/adapters/index.js.map +1 -0
- package/dist/vector/adapters/memory.adapter.d.ts +85 -0
- package/dist/vector/adapters/memory.adapter.js +505 -0
- package/dist/vector/adapters/memory.adapter.js.map +1 -0
- package/dist/vector/adapters/pinecone.adapter.d.ts +52 -0
- package/dist/vector/adapters/pinecone.adapter.js +400 -0
- package/dist/vector/adapters/pinecone.adapter.js.map +1 -0
- package/dist/vector/adapters/qdrant.adapter.d.ts +56 -0
- package/dist/vector/adapters/qdrant.adapter.js +392 -0
- package/dist/vector/adapters/qdrant.adapter.js.map +1 -0
- package/dist/vector/adapters/weaviate.adapter.d.ts +64 -0
- package/dist/vector/adapters/weaviate.adapter.js +478 -0
- package/dist/vector/adapters/weaviate.adapter.js.map +1 -0
- package/dist/vector/index.d.ts +47 -0
- package/dist/vector/index.js +72 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/types/connection.interface.d.ts +151 -0
- package/dist/vector/types/connection.interface.js +8 -0
- package/dist/vector/types/connection.interface.js.map +1 -0
- package/dist/vector/types/embedding.interface.d.ts +144 -0
- package/dist/vector/types/embedding.interface.js +8 -0
- package/dist/vector/types/embedding.interface.js.map +1 -0
- package/dist/vector/types/enums.d.ts +104 -0
- package/dist/vector/types/enums.js +113 -0
- package/dist/vector/types/enums.js.map +1 -0
- package/dist/vector/types/index.d.ts +9 -0
- package/dist/vector/types/index.js +16 -0
- package/dist/vector/types/index.js.map +1 -0
- package/dist/vector/types/vector.interface.d.ts +315 -0
- package/dist/vector/types/vector.interface.js +8 -0
- package/dist/vector/types/vector.interface.js.map +1 -0
- package/dist/vector/utils/index.d.ts +6 -0
- package/dist/vector/utils/index.js +11 -0
- package/dist/vector/utils/index.js.map +1 -0
- package/dist/vector/utils/vector-error.d.ts +69 -0
- package/dist/vector/utils/vector-error.js +117 -0
- package/dist/vector/utils/vector-error.js.map +1 -0
- package/dist/vector/vector-database.service.d.ts +405 -0
- package/dist/vector/vector-database.service.js +544 -0
- package/dist/vector/vector-database.service.js.map +1 -0
- package/dist/vector/vector.service.d.ts +245 -0
- package/dist/vector/vector.service.js +381 -0
- package/dist/vector/vector.service.js.map +1 -0
- package/dist/workflows/index.d.ts +30 -0
- package/dist/workflows/index.js +64 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/types/index.d.ts +6 -0
- package/dist/workflows/types/index.js +23 -0
- package/dist/workflows/types/index.js.map +1 -0
- package/dist/workflows/types/workflows.types.d.ts +1035 -0
- package/dist/workflows/types/workflows.types.js +13 -0
- package/dist/workflows/types/workflows.types.js.map +1 -0
- package/dist/workflows/workflow-builder.d.ts +70 -0
- package/dist/workflows/workflow-builder.js +338 -0
- package/dist/workflows/workflow-builder.js.map +1 -0
- package/dist/workflows/workflow-executor.d.ts +205 -0
- package/dist/workflows/workflow-executor.js +1186 -0
- package/dist/workflows/workflow-executor.js.map +1 -0
- package/dist/workflows/workflows.service.d.ts +398 -0
- package/dist/workflows/workflows.service.js +1595 -0
- package/dist/workflows/workflows.service.js.map +1 -0
- package/package.json +16 -13
- package/dist/actions/actions.repo.d.ts +0 -0
- package/dist/actions/actions.repo.js +0 -13
- package/dist/actions/actions.repo.js.map +0 -1
- package/dist/actions/actions.service.d.ts +0 -0
- package/dist/actions/actions.service.js +0 -24
- package/dist/actions/actions.service.js.map +0 -1
- package/dist/actions/utils/actions.util.read.d.ts +0 -0
- package/dist/actions/utils/actions.util.read.js +0 -427
- package/dist/actions/utils/actions.util.read.js.map +0 -1
- package/dist/api/services/integrationsApi.service.d.ts +0 -18
- package/dist/api/services/integrationsApi.service.js +0 -80
- package/dist/api/services/integrationsApi.service.js.map +0 -1
- package/dist/api/services/workspaceSecretsApi.service.d.ts +0 -75
- package/dist/api/services/workspaceSecretsApi.service.js +0 -62
- package/dist/api/services/workspaceSecretsApi.service.js.map +0 -1
- package/dist/appBuilder/services/app.service.d.ts +0 -111
- package/dist/appBuilder/services/app.service.js +0 -737
- package/dist/appBuilder/services/app.service.js.map +0 -1
- package/dist/appBuilder/services/appBuilder.service.d.ts +0 -111
- package/dist/appBuilder/services/appBuilder.service.js +0 -662
- package/dist/appBuilder/services/appBuilder.service.js.map +0 -1
- package/dist/appBuilder/utils/objects.utils.d.ts +0 -3
- package/dist/appBuilder/utils/objects.utils.js +0 -9
- package/dist/appBuilder/utils/objects.utils.js.map +0 -1
- package/dist/appBuilder/utils/string.utils.d.ts +0 -2
- package/dist/appBuilder/utils/string.utils.js +0 -57
- package/dist/appBuilder/utils/string.utils.js.map +0 -1
- package/dist/appBuilder/validators/index.d.ts +0 -19
- package/dist/appBuilder/validators/index.js +0 -40
- package/dist/appBuilder/validators/index.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.app.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js +0 -10
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js +0 -20
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.d.ts +0 -7
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js +0 -44
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js +0 -31
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js +0 -11
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/sample.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/sample.validator.js +0 -26
- package/dist/appBuilder/validators/joi-validators/sample.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.app.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js +0 -34
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js +0 -23
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js +0 -21
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js +0 -19
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js +0 -27
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/clients/integrations.client.d.ts +0 -2
- package/dist/clients/integrations.client.js +0 -26
- package/dist/clients/integrations.client.js.map +0 -1
- package/dist/database/database.service.d.ts +0 -232
- package/dist/database/database.service.js +0 -802
- package/dist/database/database.service.js.map +0 -1
- package/dist/database/types/aggregation.types.d.ts +0 -261
- package/dist/database/types/aggregation.types.js +0 -21
- package/dist/database/types/aggregation.types.js.map +0 -1
- package/dist/database/types/connection.types.d.ts +0 -132
- package/dist/database/types/connection.types.js +0 -6
- package/dist/database/types/connection.types.js.map +0 -1
- package/dist/database/types/database.types.d.ts +0 -175
- package/dist/database/types/database.types.js +0 -75
- package/dist/database/types/database.types.js.map +0 -1
- package/dist/database/types/index.types.d.ts +0 -220
- package/dist/database/types/index.types.js +0 -27
- package/dist/database/types/index.types.js.map +0 -1
- package/dist/database/types/migration.types.d.ts +0 -205
- package/dist/database/types/migration.types.js +0 -44
- package/dist/database/types/migration.types.js.map +0 -1
- package/dist/database/types/query.types.d.ts +0 -305
- package/dist/database/types/query.types.js +0 -57
- package/dist/database/types/query.types.js.map +0 -1
- package/dist/database/types/result.types.d.ts +0 -220
- package/dist/database/types/result.types.js +0 -6
- package/dist/database/types/result.types.js.map +0 -1
- package/dist/database/types/schema.types.d.ts +0 -190
- package/dist/database/types/schema.types.js +0 -69
- package/dist/database/types/schema.types.js.map +0 -1
- package/dist/database/utils/helpers.d.ts +0 -66
- package/dist/database/utils/helpers.js +0 -501
- package/dist/database/utils/helpers.js.map +0 -1
- package/dist/database/utils/migration.utils.d.ts +0 -151
- package/dist/database/utils/migration.utils.js +0 -476
- package/dist/database/utils/migration.utils.js.map +0 -1
- package/dist/database/utils/transaction.d.ts +0 -64
- package/dist/database/utils/transaction.js +0 -130
- package/dist/database/utils/transaction.js.map +0 -1
- package/dist/database/validators/connection.validator.d.ts +0 -20
- package/dist/database/validators/connection.validator.js +0 -267
- package/dist/database/validators/connection.validator.js.map +0 -1
- package/dist/database/validators/query.validator.d.ts +0 -31
- package/dist/database/validators/query.validator.js +0 -305
- package/dist/database/validators/query.validator.js.map +0 -1
- package/dist/database/validators/schema.validator.d.ts +0 -31
- package/dist/database/validators/schema.validator.js +0 -334
- package/dist/database/validators/schema.validator.js.map +0 -1
- package/dist/graph/graph.service.d.ts +0 -278
- package/dist/graph/graph.service.js +0 -687
- package/dist/graph/graph.service.js.map +0 -1
- package/dist/graph/types/connection.types.d.ts +0 -158
- package/dist/graph/types/connection.types.js +0 -43
- package/dist/graph/types/connection.types.js.map +0 -1
- package/dist/graph/types/graph.types.d.ts +0 -144
- package/dist/graph/types/graph.types.js +0 -84
- package/dist/graph/types/graph.types.js.map +0 -1
- package/dist/graph/types/node.types.d.ts +0 -193
- package/dist/graph/types/node.types.js +0 -49
- package/dist/graph/types/node.types.js.map +0 -1
- package/dist/graph/types/path.types.d.ts +0 -224
- package/dist/graph/types/path.types.js +0 -38
- package/dist/graph/types/path.types.js.map +0 -1
- package/dist/graph/types/query.types.d.ts +0 -247
- package/dist/graph/types/query.types.js +0 -23
- package/dist/graph/types/query.types.js.map +0 -1
- package/dist/graph/types/relationship.types.d.ts +0 -224
- package/dist/graph/types/relationship.types.js +0 -35
- package/dist/graph/types/relationship.types.js.map +0 -1
- package/dist/graph/types/result.types.d.ts +0 -237
- package/dist/graph/types/result.types.js +0 -7
- package/dist/graph/types/result.types.js.map +0 -1
- package/dist/graph/validators/index.d.ts +0 -81
- package/dist/graph/validators/index.js +0 -243
- package/dist/graph/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/services/integration.service.d.ts +0 -138
- package/dist/integrationsBuilder/services/integration.service.js +0 -1148
- package/dist/integrationsBuilder/services/integration.service.js.map +0 -1
- package/dist/integrationsBuilder/services/integrationBuilder.service.d.ts +0 -130
- package/dist/integrationsBuilder/services/integrationBuilder.service.js +0 -1017
- package/dist/integrationsBuilder/services/integrationBuilder.service.js.map +0 -1
- package/dist/integrationsBuilder/utils/objects.utils.d.ts +0 -2
- package/dist/integrationsBuilder/utils/objects.utils.js +0 -48
- package/dist/integrationsBuilder/utils/objects.utils.js.map +0 -1
- package/dist/integrationsBuilder/utils/string.utils.d.ts +0 -1
- package/dist/integrationsBuilder/utils/string.utils.js +0 -9
- package/dist/integrationsBuilder/utils/string.utils.js.map +0 -1
- package/dist/integrationsBuilder/validators/index.d.ts +0 -18
- package/dist/integrationsBuilder/validators/index.js +0 -38
- package/dist/integrationsBuilder/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.d.ts +0 -4
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js +0 -26
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js +0 -60
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js +0 -9
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js.map +0 -1
- package/dist/postman.d.ts +0 -1
- package/dist/postman.js +0 -21674
- package/dist/postman.js.map +0 -1
- package/dist/processor/utils/mongo.util.d.ts +0 -0
- package/dist/processor/utils/mongo.util.js +0 -152
- package/dist/processor/utils/mongo.util.js.map +0 -1
- package/dist/processor/utils/postgres.util.d.ts +0 -14
- package/dist/processor/utils/postgres.util.js +0 -83
- package/dist/processor/utils/postgres.util.js.map +0 -1
- package/dist/products/services/utils/crypt.utils.d.ts +0 -1
- package/dist/products/services/utils/crypt.utils.js +0 -17
- package/dist/products/services/utils/crypt.utils.js.map +0 -1
- package/dist/products/services/utils/functions.utils.d.ts +0 -13
- package/dist/products/services/utils/functions.utils.js +0 -289
- package/dist/products/services/utils/functions.utils.js.map +0 -1
- package/dist/products/services/utils/objects.utils.d.ts +0 -13
- package/dist/products/services/utils/objects.utils.js +0 -89
- package/dist/products/services/utils/objects.utils.js.map +0 -1
- package/dist/products/services/utils/string.utils.d.ts +0 -12
- package/dist/products/services/utils/string.utils.js +0 -168
- package/dist/products/services/utils/string.utils.js.map +0 -1
- package/dist/products/validators/joi-validators/create.product.validator.d.ts +0 -3
- package/dist/products/validators/joi-validators/create.product.validator.js +0 -10
- package/dist/products/validators/joi-validators/create.product.validator.js.map +0 -1
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.d.ts +0 -14
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +0 -696
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +0 -1
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +0 -7
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +0 -72
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +0 -1
- package/dist/test.appBuilder.js +0 -14
- package/dist/test.appBuilder.js.map +0 -1
- package/dist/test.import.d.ts +0 -0
- package/dist/test.import.js +0 -24
- package/dist/test.import.js.map +0 -1
- package/dist/test.imports.js +0 -28
- package/dist/test.imports.js.map +0 -1
- package/dist/test.integrationBuilder.js +0 -276
- package/dist/test.integrationBuilder.js.map +0 -1
- package/dist/test.processor.d.ts +0 -1
- package/dist/test.processor.js +0 -23
- package/dist/test.processor.js.map +0 -1
- package/dist/test.utils.d.ts +0 -1
- package/dist/test.utils.js +0 -25
- package/dist/test.utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/integrationsBuilder.types.d.ts +0 -276
- package/dist/types/integrationsBuilder.types.js +0 -51
- package/dist/types/integrationsBuilder.types.js.map +0 -1
- /package/dist/{test.appBuilder.d.ts → test/test.database.d.ts} +0 -0
- /package/dist/{test.imports.d.ts → test/test.storage.d.ts} +0 -0
- /package/dist/{test.integrationBuilder.d.ts → test/test.triggers.d.ts} +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* PostgreSQL
|
|
4
|
-
*
|
|
3
|
+
* PostgreSQL Adapter
|
|
4
|
+
*
|
|
5
|
+
* Database adapter for PostgreSQL databases using the 'pg' library.
|
|
6
|
+
* Implements all methods from BaseAdapter with PostgreSQL-specific optimizations.
|
|
5
7
|
*/
|
|
6
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
9
|
if (k2 === undefined) k2 = k;
|
|
@@ -39,1563 +41,1291 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
42
|
exports.PostgreSQLAdapter = void 0;
|
|
41
43
|
const base_adapter_1 = require("./base.adapter");
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const schema_types_1 = require("../types/schema.types");
|
|
45
|
-
const migration_types_1 = require("../types/migration.types");
|
|
46
|
-
/**
|
|
47
|
-
* PostgreSQL Connection wrapper
|
|
48
|
-
*/
|
|
49
|
-
class PostgreSQLConnection {
|
|
50
|
-
constructor(id, pool) {
|
|
51
|
-
this.id = id;
|
|
52
|
-
this.type = database_types_1.DatabaseType.POSTGRESQL;
|
|
53
|
-
this.status = database_types_1.ConnectionStatus.CONNECTED;
|
|
54
|
-
this.pool = pool;
|
|
55
|
-
}
|
|
56
|
-
async connect() {
|
|
57
|
-
this.status = database_types_1.ConnectionStatus.CONNECTED;
|
|
58
|
-
}
|
|
59
|
-
async disconnect() {
|
|
60
|
-
if (this.pool) {
|
|
61
|
-
await this.pool.end();
|
|
62
|
-
this.status = database_types_1.ConnectionStatus.DISCONNECTED;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
isConnected() {
|
|
66
|
-
return this.status === database_types_1.ConnectionStatus.CONNECTED;
|
|
67
|
-
}
|
|
68
|
-
getClient() {
|
|
69
|
-
return this.pool;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
44
|
+
const enums_1 = require("../types/enums");
|
|
45
|
+
const database_error_1 = require("../utils/database-error");
|
|
72
46
|
/**
|
|
73
|
-
* PostgreSQL
|
|
47
|
+
* PostgreSQL database adapter
|
|
48
|
+
* Provides PostgreSQL-specific implementations for all database operations
|
|
74
49
|
*/
|
|
75
|
-
class
|
|
76
|
-
constructor(name, transaction, client) {
|
|
77
|
-
this.name = name;
|
|
78
|
-
this.transaction = transaction;
|
|
79
|
-
this.createdAt = new Date();
|
|
80
|
-
this.client = client;
|
|
81
|
-
}
|
|
82
|
-
async rollback() {
|
|
83
|
-
await this.client.query(`ROLLBACK TO SAVEPOINT ${this.name}`);
|
|
84
|
-
}
|
|
85
|
-
async release() {
|
|
86
|
-
await this.client.query(`RELEASE SAVEPOINT ${this.name}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* PostgreSQL Transaction implementation
|
|
91
|
-
*/
|
|
92
|
-
class PostgreSQLTransaction {
|
|
93
|
-
constructor(connection, client, options) {
|
|
94
|
-
this.id = (0, uuid_1.v4)();
|
|
95
|
-
this.connection = connection;
|
|
96
|
-
this.status = database_types_1.TransactionStatus.ACTIVE;
|
|
97
|
-
this.isolationLevel = options === null || options === void 0 ? void 0 : options.isolationLevel;
|
|
98
|
-
this.createdAt = new Date();
|
|
99
|
-
this.client = client;
|
|
100
|
-
this.native = client;
|
|
101
|
-
}
|
|
102
|
-
async commit() {
|
|
103
|
-
if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
|
|
104
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot commit transaction: status is ${this.status}`);
|
|
105
|
-
}
|
|
106
|
-
await this.client.query('COMMIT');
|
|
107
|
-
this.status = database_types_1.TransactionStatus.COMMITTED;
|
|
108
|
-
}
|
|
109
|
-
async rollback() {
|
|
110
|
-
if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
|
|
111
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot rollback transaction: status is ${this.status}`);
|
|
112
|
-
}
|
|
113
|
-
await this.client.query('ROLLBACK');
|
|
114
|
-
this.status = database_types_1.TransactionStatus.ROLLED_BACK;
|
|
115
|
-
}
|
|
116
|
-
async savepoint(name) {
|
|
117
|
-
if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
|
|
118
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot create savepoint: transaction status is ${this.status}`);
|
|
119
|
-
}
|
|
120
|
-
await this.client.query(`SAVEPOINT ${name}`);
|
|
121
|
-
return new PostgreSQLSavepoint(name, this, this.client);
|
|
122
|
-
}
|
|
123
|
-
isActive() {
|
|
124
|
-
return this.status === database_types_1.TransactionStatus.ACTIVE;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* PostgreSQL Adapter
|
|
129
|
-
*/
|
|
130
|
-
class PostgreSQLAdapter extends base_adapter_1.BaseDatabaseAdapter {
|
|
50
|
+
class PostgreSQLAdapter extends base_adapter_1.BaseAdapter {
|
|
131
51
|
constructor() {
|
|
132
52
|
super(...arguments);
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
53
|
+
this.databaseType = enums_1.DatabaseType.POSTGRESQL;
|
|
54
|
+
this.pool = null;
|
|
135
55
|
}
|
|
136
|
-
// ====================
|
|
137
|
-
async connect(
|
|
56
|
+
// ==================== CONNECTION METHODS ====================
|
|
57
|
+
async connect(options) {
|
|
138
58
|
try {
|
|
139
|
-
//
|
|
59
|
+
// Dynamic import of pg to avoid bundling issues
|
|
140
60
|
const { Pool } = await Promise.resolve().then(() => __importStar(require('pg')));
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const pool = new Pool({
|
|
145
|
-
host: options.host,
|
|
146
|
-
port: options.port || 5432,
|
|
147
|
-
database: config.database || options.database,
|
|
148
|
-
user: options.user || options.username,
|
|
149
|
-
password: options.password,
|
|
150
|
-
ssl: options.ssl,
|
|
61
|
+
this.connectionUrl = options.connectionUrl;
|
|
62
|
+
this.pool = new Pool({
|
|
63
|
+
connectionString: options.connectionUrl,
|
|
151
64
|
max: options.poolSize || 10,
|
|
152
|
-
connectionTimeoutMillis: options.connectionTimeout || 5000,
|
|
153
65
|
idleTimeoutMillis: options.idleTimeout || 30000,
|
|
66
|
+
connectionTimeoutMillis: options.connectionTimeout || 5000,
|
|
67
|
+
ssl: options.ssl ? { rejectUnauthorized: false } : undefined,
|
|
154
68
|
});
|
|
155
|
-
// Test connection
|
|
156
|
-
await pool.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
69
|
+
// Test the connection
|
|
70
|
+
const client = await this.pool.connect();
|
|
71
|
+
const versionResult = await client.query('SELECT version()');
|
|
72
|
+
client.release();
|
|
73
|
+
this.client = this.pool;
|
|
74
|
+
this.connected = true;
|
|
75
|
+
return {
|
|
76
|
+
connected: true,
|
|
77
|
+
version: versionResult.rows[0].version,
|
|
78
|
+
};
|
|
163
79
|
}
|
|
164
80
|
catch (error) {
|
|
165
|
-
throw
|
|
81
|
+
throw database_error_1.DatabaseError.connectionError(`Failed to connect to PostgreSQL: ${error.message}`, error);
|
|
166
82
|
}
|
|
167
83
|
}
|
|
168
|
-
async
|
|
169
|
-
await connection.disconnect();
|
|
170
|
-
this.connectionPool.delete(connection.id);
|
|
171
|
-
}
|
|
172
|
-
async testConnection(connection) {
|
|
173
|
-
var _a;
|
|
174
|
-
const startTime = Date.now();
|
|
84
|
+
async testConnection(options) {
|
|
175
85
|
try {
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
|
|
86
|
+
const { Pool } = await Promise.resolve().then(() => __importStar(require('pg')));
|
|
87
|
+
const pool = new Pool({
|
|
88
|
+
connectionString: options.connectionUrl,
|
|
89
|
+
max: 1,
|
|
90
|
+
connectionTimeoutMillis: options.connectionTimeout || 5000,
|
|
91
|
+
});
|
|
92
|
+
const client = await pool.connect();
|
|
93
|
+
const versionResult = await client.query('SELECT version()');
|
|
94
|
+
client.release();
|
|
95
|
+
await pool.end();
|
|
179
96
|
return {
|
|
180
97
|
connected: true,
|
|
181
|
-
|
|
182
|
-
databaseType: 'PostgreSQL',
|
|
183
|
-
version: (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.version,
|
|
184
|
-
responseTime,
|
|
98
|
+
version: versionResult.rows[0].version,
|
|
185
99
|
};
|
|
186
100
|
}
|
|
187
101
|
catch (error) {
|
|
188
102
|
return {
|
|
189
103
|
connected: false,
|
|
190
|
-
message: 'Failed to connect to PostgreSQL',
|
|
191
|
-
databaseType: 'PostgreSQL',
|
|
192
|
-
responseTime: Date.now() - startTime,
|
|
193
|
-
error: error.message,
|
|
194
104
|
};
|
|
195
105
|
}
|
|
196
106
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
let beginStatement = 'BEGIN';
|
|
204
|
-
if (options === null || options === void 0 ? void 0 : options.isolationLevel) {
|
|
205
|
-
beginStatement += ` ISOLATION LEVEL ${options.isolationLevel.replace('_', ' ')}`;
|
|
206
|
-
}
|
|
207
|
-
if (options === null || options === void 0 ? void 0 : options.readOnly) {
|
|
208
|
-
beginStatement += ' READ ONLY';
|
|
209
|
-
}
|
|
210
|
-
if (options === null || options === void 0 ? void 0 : options.deferrable) {
|
|
211
|
-
beginStatement += ' DEFERRABLE';
|
|
212
|
-
}
|
|
213
|
-
await client.query(beginStatement);
|
|
214
|
-
return new PostgreSQLTransaction(connection, client, options);
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Failed to begin transaction: ${error.message}`, error);
|
|
107
|
+
async disconnect() {
|
|
108
|
+
if (this.pool) {
|
|
109
|
+
await this.pool.end();
|
|
110
|
+
this.pool = null;
|
|
111
|
+
this.client = null;
|
|
112
|
+
this.connected = false;
|
|
218
113
|
}
|
|
219
114
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
await transaction.rollback();
|
|
225
|
-
}
|
|
226
|
-
async createSavepoint(connection, transaction, savepointName) {
|
|
227
|
-
return transaction.savepoint(savepointName);
|
|
228
|
-
}
|
|
229
|
-
async rollbackToSavepoint(_connection, _transaction, savepoint) {
|
|
230
|
-
await savepoint.rollback();
|
|
231
|
-
}
|
|
232
|
-
async releaseSavepoint(_connection, _transaction, savepoint) {
|
|
233
|
-
await savepoint.release();
|
|
234
|
-
}
|
|
235
|
-
// ==================== Query Methods ====================
|
|
236
|
-
async query(connection, options) {
|
|
237
|
-
const startTime = Date.now();
|
|
115
|
+
// ==================== QUERY METHODS ====================
|
|
116
|
+
async query(query) {
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
this.ensureConnected();
|
|
238
119
|
try {
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
120
|
+
const client = ((_a = query.options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
121
|
+
const result = await client.query(query.sql, query.params);
|
|
122
|
+
// Get total count if needed for pagination
|
|
123
|
+
let count = result.rows.length;
|
|
124
|
+
if (query.options.limit || query.options.offset) {
|
|
125
|
+
const countSql = this.buildCountQuery(query);
|
|
126
|
+
// Calculate how many params to remove based on actual pagination options
|
|
127
|
+
let paramsToRemove = 0;
|
|
128
|
+
if (query.options.limit !== undefined)
|
|
129
|
+
paramsToRemove++;
|
|
130
|
+
if (query.options.offset !== undefined)
|
|
131
|
+
paramsToRemove++;
|
|
132
|
+
const countParams = paramsToRemove > 0 ? (_b = query.params) === null || _b === void 0 ? void 0 : _b.slice(0, -paramsToRemove) : query.params;
|
|
133
|
+
const countResult = await client.query(countSql, countParams);
|
|
134
|
+
count = parseInt(countResult.rows[0].count, 10);
|
|
135
|
+
}
|
|
243
136
|
return {
|
|
244
137
|
data: result.rows,
|
|
245
|
-
count
|
|
246
|
-
|
|
247
|
-
databaseType: 'PostgreSQL',
|
|
138
|
+
count,
|
|
139
|
+
fields: (_c = result.fields) === null || _c === void 0 ? void 0 : _c.map((f) => f.name),
|
|
248
140
|
};
|
|
249
141
|
}
|
|
250
142
|
catch (error) {
|
|
251
|
-
throw
|
|
143
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
252
144
|
}
|
|
253
145
|
}
|
|
254
|
-
async
|
|
255
|
-
|
|
146
|
+
async raw(options) {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
this.ensureConnected();
|
|
256
149
|
try {
|
|
257
|
-
const
|
|
258
|
-
const
|
|
259
|
-
const result = await client.query(query, params);
|
|
260
|
-
const executionTime = Date.now() - startTime;
|
|
150
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
151
|
+
const result = await client.query(options.query, options.params);
|
|
261
152
|
return {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
executionTime,
|
|
266
|
-
success: true,
|
|
153
|
+
data: result.rows,
|
|
154
|
+
count: result.rowCount || result.rows.length,
|
|
155
|
+
fields: (_b = result.fields) === null || _b === void 0 ? void 0 : _b.map((f) => f.name),
|
|
267
156
|
};
|
|
268
157
|
}
|
|
269
158
|
catch (error) {
|
|
270
|
-
throw
|
|
159
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
271
160
|
}
|
|
272
161
|
}
|
|
273
|
-
|
|
274
|
-
|
|
162
|
+
// ==================== WRITE METHODS ====================
|
|
163
|
+
async insert(options) {
|
|
164
|
+
var _a;
|
|
165
|
+
this.ensureConnected();
|
|
275
166
|
try {
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
167
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
168
|
+
const data = Array.isArray(options.data) ? options.data : [options.data];
|
|
169
|
+
if (data.length === 0) {
|
|
170
|
+
return { data: [], count: 0, insertedIds: [] };
|
|
171
|
+
}
|
|
172
|
+
const columns = Object.keys(data[0]);
|
|
173
|
+
const values = [];
|
|
174
|
+
const valuePlaceholders = [];
|
|
175
|
+
data.forEach((record, rowIndex) => {
|
|
176
|
+
const rowPlaceholders = [];
|
|
177
|
+
columns.forEach((col, colIndex) => {
|
|
178
|
+
values.push(record[col]);
|
|
179
|
+
rowPlaceholders.push(`$${rowIndex * columns.length + colIndex + 1}`);
|
|
180
|
+
});
|
|
181
|
+
valuePlaceholders.push(`(${rowPlaceholders.join(', ')})`);
|
|
182
|
+
});
|
|
183
|
+
let sql = `INSERT INTO ${this.escapeIdentifier(options.table)} (${columns.map(c => this.escapeIdentifier(c)).join(', ')}) VALUES ${valuePlaceholders.join(', ')}`;
|
|
184
|
+
// Handle ON CONFLICT (upsert)
|
|
185
|
+
if (options.onConflict) {
|
|
186
|
+
const conflictColumns = options.onConflict.columns.map(c => this.escapeIdentifier(c)).join(', ');
|
|
187
|
+
if (options.onConflict.action === 'ignore') {
|
|
188
|
+
sql += ` ON CONFLICT (${conflictColumns}) DO NOTHING`;
|
|
189
|
+
}
|
|
190
|
+
else if (options.onConflict.action === 'update' && options.onConflict.update) {
|
|
191
|
+
const updates = options.onConflict.update.map(col => `${this.escapeIdentifier(col)} = EXCLUDED.${this.escapeIdentifier(col)}`).join(', ');
|
|
192
|
+
sql += ` ON CONFLICT (${conflictColumns}) DO UPDATE SET ${updates}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Always use RETURNING * to get all columns including the primary key
|
|
196
|
+
// This avoids assuming the primary key column is named 'id'
|
|
197
|
+
sql += ' RETURNING *';
|
|
198
|
+
const result = await client.query(sql, values);
|
|
199
|
+
// Try to extract the primary key value from returned rows
|
|
200
|
+
// Look for common primary key column names if 'id' doesn't exist
|
|
201
|
+
const insertedIds = result.rows.map((r) => {
|
|
202
|
+
// Try common primary key column names in order of likelihood
|
|
203
|
+
if (r.id !== undefined)
|
|
204
|
+
return r.id;
|
|
205
|
+
if (r._id !== undefined)
|
|
206
|
+
return r._id;
|
|
207
|
+
if (r.uuid !== undefined)
|
|
208
|
+
return r.uuid;
|
|
209
|
+
// Fall back to first column value as a reasonable guess for serial PKs
|
|
210
|
+
const keys = Object.keys(r);
|
|
211
|
+
return keys.length > 0 ? r[keys[0]] : undefined;
|
|
212
|
+
});
|
|
280
213
|
return {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
executionTime,
|
|
285
|
-
success: true,
|
|
214
|
+
data: options.returning ? result.rows : [],
|
|
215
|
+
count: result.rowCount || data.length,
|
|
216
|
+
insertedIds,
|
|
286
217
|
};
|
|
287
218
|
}
|
|
288
219
|
catch (error) {
|
|
289
|
-
throw
|
|
220
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
290
221
|
}
|
|
291
222
|
}
|
|
292
|
-
async
|
|
293
|
-
|
|
223
|
+
async update(options) {
|
|
224
|
+
var _a;
|
|
225
|
+
this.ensureConnected();
|
|
294
226
|
try {
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
|
|
227
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
228
|
+
const setClauses = [];
|
|
229
|
+
const values = [];
|
|
230
|
+
let paramIndex = 1;
|
|
231
|
+
// Build SET clause
|
|
232
|
+
for (const [key, value] of Object.entries(options.data)) {
|
|
233
|
+
if (value && typeof value === 'object' && this.isUpdateOperator(value)) {
|
|
234
|
+
// Handle update operators
|
|
235
|
+
if ('$INC' in value) {
|
|
236
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ${this.escapeIdentifier(key)} + $${paramIndex}`);
|
|
237
|
+
values.push(value.$INC);
|
|
238
|
+
paramIndex++;
|
|
239
|
+
}
|
|
240
|
+
else if ('$DEC' in value) {
|
|
241
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ${this.escapeIdentifier(key)} - $${paramIndex}`);
|
|
242
|
+
values.push(value.$DEC);
|
|
243
|
+
paramIndex++;
|
|
244
|
+
}
|
|
245
|
+
else if ('$MUL' in value) {
|
|
246
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ${this.escapeIdentifier(key)} * $${paramIndex}`);
|
|
247
|
+
values.push(value.$MUL);
|
|
248
|
+
paramIndex++;
|
|
249
|
+
}
|
|
250
|
+
else if ('$MIN' in value) {
|
|
251
|
+
// LEAST function for minimum
|
|
252
|
+
setClauses.push(`${this.escapeIdentifier(key)} = LEAST(${this.escapeIdentifier(key)}, $${paramIndex})`);
|
|
253
|
+
values.push(value.$MIN);
|
|
254
|
+
paramIndex++;
|
|
255
|
+
}
|
|
256
|
+
else if ('$MAX' in value) {
|
|
257
|
+
// GREATEST function for maximum
|
|
258
|
+
setClauses.push(`${this.escapeIdentifier(key)} = GREATEST(${this.escapeIdentifier(key)}, $${paramIndex})`);
|
|
259
|
+
values.push(value.$MAX);
|
|
260
|
+
paramIndex++;
|
|
261
|
+
}
|
|
262
|
+
else if ('$SET' in value) {
|
|
263
|
+
setClauses.push(`${this.escapeIdentifier(key)} = $${paramIndex}`);
|
|
264
|
+
values.push(value.$SET);
|
|
265
|
+
paramIndex++;
|
|
266
|
+
}
|
|
267
|
+
else if ('$UNSET' in value && value.$UNSET) {
|
|
268
|
+
setClauses.push(`${this.escapeIdentifier(key)} = NULL`);
|
|
269
|
+
// No paramIndex increment needed for NULL
|
|
270
|
+
}
|
|
271
|
+
else if ('$PUSH' in value) {
|
|
272
|
+
// Array append for PostgreSQL (column must be array type)
|
|
273
|
+
setClauses.push(`${this.escapeIdentifier(key)} = array_append(${this.escapeIdentifier(key)}, $${paramIndex})`);
|
|
274
|
+
values.push(value.$PUSH);
|
|
275
|
+
paramIndex++;
|
|
276
|
+
}
|
|
277
|
+
else if ('$PULL' in value) {
|
|
278
|
+
// Array remove for PostgreSQL (column must be array type)
|
|
279
|
+
setClauses.push(`${this.escapeIdentifier(key)} = array_remove(${this.escapeIdentifier(key)}, $${paramIndex})`);
|
|
280
|
+
values.push(value.$PULL);
|
|
281
|
+
paramIndex++;
|
|
282
|
+
}
|
|
283
|
+
else if ('$ADDTOSET' in value) {
|
|
284
|
+
// Add unique value to array - use CASE to check existence first
|
|
285
|
+
setClauses.push(`${this.escapeIdentifier(key)} = CASE WHEN $${paramIndex} = ANY(${this.escapeIdentifier(key)}) THEN ${this.escapeIdentifier(key)} ELSE array_append(${this.escapeIdentifier(key)}, $${paramIndex}) END`);
|
|
286
|
+
values.push(value.$ADDTOSET);
|
|
287
|
+
paramIndex++;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
setClauses.push(`${this.escapeIdentifier(key)} = $${paramIndex}`);
|
|
292
|
+
values.push(value);
|
|
293
|
+
paramIndex++;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
let sql = `UPDATE ${this.escapeIdentifier(options.table)} SET ${setClauses.join(', ')}`;
|
|
297
|
+
// Build WHERE clause
|
|
298
|
+
if (options.where) {
|
|
299
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, paramIndex);
|
|
300
|
+
sql += ` WHERE ${whereClause}`;
|
|
301
|
+
values.push(...whereParams);
|
|
302
|
+
}
|
|
303
|
+
// Add RETURNING if requested
|
|
304
|
+
if (options.returning) {
|
|
305
|
+
sql += ' RETURNING *';
|
|
306
|
+
}
|
|
307
|
+
const result = await client.query(sql, values);
|
|
299
308
|
return {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
executionTime,
|
|
303
|
-
success: true,
|
|
309
|
+
data: options.returning ? result.rows : [],
|
|
310
|
+
count: result.rowCount || 0,
|
|
304
311
|
};
|
|
305
312
|
}
|
|
306
313
|
catch (error) {
|
|
307
|
-
throw
|
|
314
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
308
315
|
}
|
|
309
316
|
}
|
|
310
|
-
async
|
|
311
|
-
|
|
317
|
+
async delete(options) {
|
|
318
|
+
var _a;
|
|
319
|
+
this.ensureConnected();
|
|
312
320
|
try {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
321
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
322
|
+
let sql = `DELETE FROM ${this.escapeIdentifier(options.table)}`;
|
|
323
|
+
const values = [];
|
|
324
|
+
// Build WHERE clause
|
|
325
|
+
if (options.where) {
|
|
326
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, 1);
|
|
327
|
+
sql += ` WHERE ${whereClause}`;
|
|
328
|
+
values.push(...whereParams);
|
|
329
|
+
}
|
|
330
|
+
// Add RETURNING if requested
|
|
331
|
+
if (options.returning) {
|
|
332
|
+
sql += ' RETURNING *';
|
|
333
|
+
}
|
|
334
|
+
const result = await client.query(sql, values);
|
|
317
335
|
return {
|
|
318
|
-
|
|
319
|
-
updatedCount: 0,
|
|
320
|
-
affectedCount: result.rowCount,
|
|
336
|
+
count: result.rowCount || 0,
|
|
321
337
|
data: options.returning ? result.rows : undefined,
|
|
322
|
-
executionTime,
|
|
323
|
-
success: true,
|
|
324
338
|
};
|
|
325
339
|
}
|
|
326
340
|
catch (error) {
|
|
327
|
-
throw
|
|
341
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
328
342
|
}
|
|
329
343
|
}
|
|
330
|
-
async
|
|
331
|
-
|
|
332
|
-
const startTime = Date.now();
|
|
344
|
+
async upsert(options) {
|
|
345
|
+
this.ensureConnected();
|
|
333
346
|
try {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
347
|
+
const insertResult = await this.insert(Object.assign(Object.assign({}, options), { onConflict: {
|
|
348
|
+
columns: options.conflictKeys,
|
|
349
|
+
action: 'update',
|
|
350
|
+
update: options.updateColumns || Object.keys(options.data).filter(k => !options.conflictKeys.includes(k)),
|
|
351
|
+
}, returning: true }));
|
|
352
|
+
// Determine if it was an insert or update
|
|
353
|
+
// PostgreSQL doesn't directly tell us, so we check xmax
|
|
354
|
+
const operation = 'upserted'; // Simplified - PostgreSQL doesn't easily distinguish
|
|
337
355
|
return {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
name: f.name,
|
|
342
|
-
type: f.dataTypeID,
|
|
343
|
-
})),
|
|
344
|
-
executionTime,
|
|
356
|
+
data: insertResult.data,
|
|
357
|
+
count: insertResult.count,
|
|
358
|
+
operation: insertResult.count > 0 ? 'inserted' : 'updated',
|
|
345
359
|
};
|
|
346
360
|
}
|
|
347
361
|
catch (error) {
|
|
348
|
-
throw
|
|
362
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
349
363
|
}
|
|
350
364
|
}
|
|
351
|
-
// ====================
|
|
352
|
-
async count(
|
|
365
|
+
// ==================== AGGREGATION METHODS ====================
|
|
366
|
+
async count(options) {
|
|
367
|
+
var _a;
|
|
368
|
+
this.ensureConnected();
|
|
353
369
|
try {
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
370
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
371
|
+
const column = options.column ? this.escapeIdentifier(options.column) : '*';
|
|
372
|
+
const distinctPrefix = options.distinct ? 'DISTINCT ' : '';
|
|
373
|
+
let sql = `SELECT COUNT(${distinctPrefix}${column}) as count FROM ${this.escapeIdentifier(options.table)}`;
|
|
374
|
+
const values = [];
|
|
375
|
+
if (options.where) {
|
|
376
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, 1);
|
|
377
|
+
sql += ` WHERE ${whereClause}`;
|
|
378
|
+
values.push(...whereParams);
|
|
379
|
+
}
|
|
380
|
+
const result = await client.query(sql, values);
|
|
357
381
|
return parseInt(result.rows[0].count, 10);
|
|
358
382
|
}
|
|
359
383
|
catch (error) {
|
|
360
|
-
throw
|
|
384
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
361
385
|
}
|
|
362
386
|
}
|
|
363
|
-
async sum(
|
|
387
|
+
async sum(options) {
|
|
388
|
+
var _a;
|
|
389
|
+
this.ensureConnected();
|
|
364
390
|
try {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
|
|
391
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
392
|
+
let sql = `SELECT COALESCE(SUM(${this.escapeIdentifier(options.column)}), 0) as sum FROM ${this.escapeIdentifier(options.table)}`;
|
|
393
|
+
const values = [];
|
|
394
|
+
if (options.where) {
|
|
395
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, 1);
|
|
396
|
+
sql += ` WHERE ${whereClause}`;
|
|
397
|
+
values.push(...whereParams);
|
|
398
|
+
}
|
|
399
|
+
const result = await client.query(sql, values);
|
|
400
|
+
return parseFloat(result.rows[0].sum);
|
|
369
401
|
}
|
|
370
402
|
catch (error) {
|
|
371
|
-
throw
|
|
403
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
372
404
|
}
|
|
373
405
|
}
|
|
374
|
-
async avg(
|
|
406
|
+
async avg(options) {
|
|
407
|
+
var _a;
|
|
408
|
+
this.ensureConnected();
|
|
375
409
|
try {
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
const
|
|
379
|
-
|
|
410
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
411
|
+
let sql = `SELECT COALESCE(AVG(${this.escapeIdentifier(options.column)}), 0) as avg FROM ${this.escapeIdentifier(options.table)}`;
|
|
412
|
+
const values = [];
|
|
413
|
+
if (options.where) {
|
|
414
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, 1);
|
|
415
|
+
sql += ` WHERE ${whereClause}`;
|
|
416
|
+
values.push(...whereParams);
|
|
417
|
+
}
|
|
418
|
+
const result = await client.query(sql, values);
|
|
419
|
+
return parseFloat(result.rows[0].avg);
|
|
380
420
|
}
|
|
381
421
|
catch (error) {
|
|
382
|
-
throw
|
|
422
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
383
423
|
}
|
|
384
424
|
}
|
|
385
|
-
async min(
|
|
425
|
+
async min(options) {
|
|
426
|
+
var _a;
|
|
427
|
+
this.ensureConnected();
|
|
386
428
|
try {
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
|
|
429
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
430
|
+
let sql = `SELECT MIN(${this.escapeIdentifier(options.column)}) as min FROM ${this.escapeIdentifier(options.table)}`;
|
|
431
|
+
const values = [];
|
|
432
|
+
if (options.where) {
|
|
433
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, 1);
|
|
434
|
+
sql += ` WHERE ${whereClause}`;
|
|
435
|
+
values.push(...whereParams);
|
|
436
|
+
}
|
|
437
|
+
const result = await client.query(sql, values);
|
|
438
|
+
return result.rows[0].min;
|
|
391
439
|
}
|
|
392
440
|
catch (error) {
|
|
393
|
-
throw
|
|
441
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
394
442
|
}
|
|
395
443
|
}
|
|
396
|
-
async max(
|
|
444
|
+
async max(options) {
|
|
445
|
+
var _a;
|
|
446
|
+
this.ensureConnected();
|
|
397
447
|
try {
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
|
|
448
|
+
const client = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
449
|
+
let sql = `SELECT MAX(${this.escapeIdentifier(options.column)}) as max FROM ${this.escapeIdentifier(options.table)}`;
|
|
450
|
+
const values = [];
|
|
451
|
+
if (options.where) {
|
|
452
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where, 1);
|
|
453
|
+
sql += ` WHERE ${whereClause}`;
|
|
454
|
+
values.push(...whereParams);
|
|
455
|
+
}
|
|
456
|
+
const result = await client.query(sql, values);
|
|
457
|
+
return result.rows[0].max;
|
|
402
458
|
}
|
|
403
459
|
catch (error) {
|
|
404
|
-
throw
|
|
460
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
405
461
|
}
|
|
406
462
|
}
|
|
407
|
-
async
|
|
463
|
+
async aggregate(builtAggregation) {
|
|
464
|
+
var _a;
|
|
465
|
+
this.ensureConnected();
|
|
408
466
|
try {
|
|
409
|
-
const
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
return result.rows;
|
|
467
|
+
const client = ((_a = builtAggregation.options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
468
|
+
const result = await client.query(builtAggregation.sql, builtAggregation.params);
|
|
469
|
+
return result.rows[0] || {};
|
|
413
470
|
}
|
|
414
471
|
catch (error) {
|
|
415
|
-
throw
|
|
472
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
416
473
|
}
|
|
417
474
|
}
|
|
418
|
-
async
|
|
475
|
+
async groupBy(builtGroupBy) {
|
|
476
|
+
var _a;
|
|
477
|
+
this.ensureConnected();
|
|
419
478
|
try {
|
|
420
|
-
const
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
479
|
+
const client = ((_a = builtGroupBy.options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
480
|
+
const result = await client.query(builtGroupBy.sql, builtGroupBy.params);
|
|
481
|
+
// Transform rows into IGroupByResult format
|
|
482
|
+
const options = builtGroupBy.options;
|
|
483
|
+
return result.rows.map((row) => {
|
|
484
|
+
var _a;
|
|
485
|
+
const group = {};
|
|
486
|
+
const aggregates = {};
|
|
487
|
+
for (const key of Object.keys(row)) {
|
|
488
|
+
if ((_a = options.groupBy) === null || _a === void 0 ? void 0 : _a.includes(key)) {
|
|
489
|
+
group[key] = row[key];
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
aggregates[key] = row[key];
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return { group, aggregates: aggregates };
|
|
496
|
+
});
|
|
424
497
|
}
|
|
425
498
|
catch (error) {
|
|
426
|
-
throw
|
|
499
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'postgresql');
|
|
427
500
|
}
|
|
428
501
|
}
|
|
429
|
-
// ====================
|
|
430
|
-
async
|
|
431
|
-
|
|
502
|
+
// ==================== TRANSACTION METHODS ====================
|
|
503
|
+
async beginTransaction(isolationLevel, readOnly, timeout) {
|
|
504
|
+
this.ensureConnected();
|
|
432
505
|
try {
|
|
433
|
-
const
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
506
|
+
const client = await this.pool.connect();
|
|
507
|
+
const id = `pg_txn_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
508
|
+
// Build BEGIN statement with isolation level
|
|
509
|
+
let beginSql = 'BEGIN';
|
|
510
|
+
if (isolationLevel) {
|
|
511
|
+
beginSql += ` ISOLATION LEVEL ${this.mapIsolationLevel(isolationLevel)}`;
|
|
512
|
+
}
|
|
513
|
+
if (readOnly) {
|
|
514
|
+
beginSql += ' READ ONLY';
|
|
515
|
+
}
|
|
516
|
+
await client.query(beginSql);
|
|
517
|
+
// Set statement timeout if specified
|
|
518
|
+
if (timeout) {
|
|
519
|
+
await client.query(`SET LOCAL statement_timeout = ${timeout}`);
|
|
520
|
+
}
|
|
437
521
|
return {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
522
|
+
id,
|
|
523
|
+
databaseType: 'postgresql',
|
|
524
|
+
isolationLevel: isolationLevel || enums_1.IsolationLevel.READ_COMMITTED,
|
|
525
|
+
readOnly: readOnly || false,
|
|
526
|
+
timeout,
|
|
527
|
+
startedAt: new Date(),
|
|
528
|
+
client,
|
|
529
|
+
savepoints: new Map(),
|
|
530
|
+
status: 'active',
|
|
442
531
|
};
|
|
443
532
|
}
|
|
444
533
|
catch (error) {
|
|
445
|
-
|
|
446
|
-
success: false,
|
|
447
|
-
operation: 'create',
|
|
448
|
-
table: schema.name,
|
|
449
|
-
error: error.message,
|
|
450
|
-
executionTime: Date.now() - startTime,
|
|
451
|
-
};
|
|
534
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to begin transaction: ${error.message}`, error);
|
|
452
535
|
}
|
|
453
536
|
}
|
|
454
|
-
async
|
|
455
|
-
const startTime = Date.now();
|
|
537
|
+
async commitTransaction(context) {
|
|
456
538
|
try {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
success: true,
|
|
461
|
-
operation: 'drop',
|
|
462
|
-
table: tableName,
|
|
463
|
-
executionTime: Date.now() - startTime,
|
|
464
|
-
};
|
|
539
|
+
await context.client.query('COMMIT');
|
|
540
|
+
context.client.release();
|
|
541
|
+
context.status = 'committed';
|
|
465
542
|
}
|
|
466
543
|
catch (error) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
table: tableName,
|
|
471
|
-
error: error.message,
|
|
472
|
-
executionTime: Date.now() - startTime,
|
|
473
|
-
};
|
|
544
|
+
context.status = 'error';
|
|
545
|
+
context.client.release();
|
|
546
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to commit transaction: ${error.message}`, error);
|
|
474
547
|
}
|
|
475
548
|
}
|
|
476
|
-
async
|
|
477
|
-
const startTime = Date.now();
|
|
549
|
+
async rollbackTransaction(context) {
|
|
478
550
|
try {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
await client.query(query);
|
|
483
|
-
}
|
|
484
|
-
return {
|
|
485
|
-
success: true,
|
|
486
|
-
operation: 'alter',
|
|
487
|
-
table: tableName,
|
|
488
|
-
executionTime: Date.now() - startTime,
|
|
489
|
-
};
|
|
551
|
+
await context.client.query('ROLLBACK');
|
|
552
|
+
context.client.release();
|
|
553
|
+
context.status = 'rolled_back';
|
|
490
554
|
}
|
|
491
555
|
catch (error) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
table: tableName,
|
|
496
|
-
error: error.message,
|
|
497
|
-
executionTime: Date.now() - startTime,
|
|
498
|
-
};
|
|
556
|
+
context.status = 'error';
|
|
557
|
+
context.client.release();
|
|
558
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to rollback transaction: ${error.message}`, error);
|
|
499
559
|
}
|
|
500
560
|
}
|
|
501
|
-
async
|
|
561
|
+
async createSavepoint(context, name) {
|
|
502
562
|
try {
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
numeric_scale
|
|
513
|
-
FROM information_schema.columns
|
|
514
|
-
WHERE table_name = $1
|
|
515
|
-
ORDER BY ordinal_position
|
|
516
|
-
`;
|
|
517
|
-
const result = await client.query(query, [tableName]);
|
|
518
|
-
const columns = result.rows.map((row) => ({
|
|
519
|
-
name: row.column_name,
|
|
520
|
-
type: this.mapPostgreSQLTypeToColumnType(row.data_type),
|
|
521
|
-
nullable: row.is_nullable === 'YES',
|
|
522
|
-
defaultValue: row.column_default,
|
|
523
|
-
length: row.character_maximum_length,
|
|
524
|
-
precision: row.numeric_precision,
|
|
525
|
-
scale: row.numeric_scale,
|
|
526
|
-
}));
|
|
527
|
-
return {
|
|
528
|
-
name: tableName,
|
|
529
|
-
columns,
|
|
563
|
+
await context.client.query(`SAVEPOINT ${this.escapeIdentifier(name)}`);
|
|
564
|
+
const savepoint = {
|
|
565
|
+
name,
|
|
566
|
+
release: async () => {
|
|
567
|
+
await this.releaseSavepoint(context, savepoint);
|
|
568
|
+
},
|
|
569
|
+
rollback: async () => {
|
|
570
|
+
await this.rollbackToSavepoint(context, savepoint);
|
|
571
|
+
},
|
|
530
572
|
};
|
|
573
|
+
context.savepoints.set(name, savepoint);
|
|
574
|
+
return savepoint;
|
|
531
575
|
}
|
|
532
576
|
catch (error) {
|
|
533
|
-
throw
|
|
577
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to create savepoint: ${error.message}`, error);
|
|
534
578
|
}
|
|
535
579
|
}
|
|
536
|
-
async
|
|
580
|
+
async releaseSavepoint(context, savepoint) {
|
|
537
581
|
try {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
SELECT tablename
|
|
541
|
-
FROM pg_tables
|
|
542
|
-
WHERE schemaname = 'public'
|
|
543
|
-
ORDER BY tablename
|
|
544
|
-
`;
|
|
545
|
-
const result = await client.query(query);
|
|
546
|
-
return result.rows.map((row) => row.tablename);
|
|
582
|
+
await context.client.query(`RELEASE SAVEPOINT ${this.escapeIdentifier(savepoint.name)}`);
|
|
583
|
+
context.savepoints.delete(savepoint.name);
|
|
547
584
|
}
|
|
548
585
|
catch (error) {
|
|
549
|
-
throw
|
|
586
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to release savepoint: ${error.message}`, error);
|
|
550
587
|
}
|
|
551
588
|
}
|
|
552
|
-
async
|
|
589
|
+
async rollbackToSavepoint(context, savepoint) {
|
|
553
590
|
try {
|
|
554
|
-
|
|
555
|
-
const query = `
|
|
556
|
-
SELECT EXISTS (
|
|
557
|
-
SELECT FROM information_schema.tables
|
|
558
|
-
WHERE table_schema = 'public'
|
|
559
|
-
AND table_name = $1
|
|
560
|
-
)
|
|
561
|
-
`;
|
|
562
|
-
const result = await client.query(query, [tableName]);
|
|
563
|
-
return result.rows[0].exists;
|
|
591
|
+
await context.client.query(`ROLLBACK TO SAVEPOINT ${this.escapeIdentifier(savepoint.name)}`);
|
|
564
592
|
}
|
|
565
593
|
catch (error) {
|
|
566
|
-
|
|
594
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to rollback to savepoint: ${error.message}`, error);
|
|
567
595
|
}
|
|
568
596
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
597
|
+
supportsSavepoints() {
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
// ==================== SCHEMA METHODS ====================
|
|
601
|
+
async createTable(definition, options) {
|
|
602
|
+
this.ensureConnected();
|
|
572
603
|
try {
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
604
|
+
const columnDefs = definition.columns.map(col => this.buildColumnDefinition(col)).join(', ');
|
|
605
|
+
let sql = 'CREATE';
|
|
606
|
+
if (options === null || options === void 0 ? void 0 : options.temporary)
|
|
607
|
+
sql += ' TEMPORARY';
|
|
608
|
+
if (options === null || options === void 0 ? void 0 : options.unlogged)
|
|
609
|
+
sql += ' UNLOGGED';
|
|
610
|
+
sql += ' TABLE';
|
|
611
|
+
if (options === null || options === void 0 ? void 0 : options.ifNotExists)
|
|
612
|
+
sql += ' IF NOT EXISTS';
|
|
613
|
+
sql += ` ${this.escapeIdentifier(definition.name)} (${columnDefs}`;
|
|
614
|
+
// Add table constraints
|
|
615
|
+
if (definition.constraints) {
|
|
616
|
+
const constraintDefs = definition.constraints.map(c => this.buildConstraintDefinition(c)).join(', ');
|
|
617
|
+
sql += `, ${constraintDefs}`;
|
|
618
|
+
}
|
|
619
|
+
sql += ')';
|
|
620
|
+
// Add inheritance
|
|
621
|
+
if (options === null || options === void 0 ? void 0 : options.inherits) {
|
|
622
|
+
sql += ` INHERITS (${this.escapeIdentifier(options.inherits)})`;
|
|
623
|
+
}
|
|
624
|
+
// Add tablespace
|
|
625
|
+
if (options === null || options === void 0 ? void 0 : options.tablespace) {
|
|
626
|
+
sql += ` TABLESPACE ${this.escapeIdentifier(options.tablespace)}`;
|
|
627
|
+
}
|
|
628
|
+
await this.pool.query(sql);
|
|
629
|
+
// Add table comment
|
|
630
|
+
if (definition.comment) {
|
|
631
|
+
await this.pool.query(`COMMENT ON TABLE ${this.escapeIdentifier(definition.name)} IS ${this.escapeValue(definition.comment)}`);
|
|
632
|
+
}
|
|
633
|
+
// Create indexes
|
|
634
|
+
if (definition.indexes) {
|
|
635
|
+
for (const index of definition.indexes) {
|
|
636
|
+
await this.createIndex(index);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
583
639
|
}
|
|
584
640
|
catch (error) {
|
|
585
|
-
|
|
586
|
-
success: false,
|
|
587
|
-
operation: 'create',
|
|
588
|
-
indexName: options.index.name,
|
|
589
|
-
table: options.table,
|
|
590
|
-
error: error.message,
|
|
591
|
-
executionTime: Date.now() - startTime,
|
|
592
|
-
};
|
|
641
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to create table: ${error.message}`, error);
|
|
593
642
|
}
|
|
594
643
|
}
|
|
595
|
-
async
|
|
596
|
-
|
|
644
|
+
async alterTable(tableName, operations) {
|
|
645
|
+
this.ensureConnected();
|
|
597
646
|
try {
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
647
|
+
for (const op of operations) {
|
|
648
|
+
let sql = `ALTER TABLE ${this.escapeIdentifier(tableName)}`;
|
|
649
|
+
switch (op.type) {
|
|
650
|
+
case 'ADD':
|
|
651
|
+
if (op.column) {
|
|
652
|
+
sql += ` ADD COLUMN ${this.buildColumnDefinition(op.column)}`;
|
|
653
|
+
}
|
|
654
|
+
else if (op.constraint) {
|
|
655
|
+
sql += ` ADD ${this.buildConstraintDefinition(op.constraint)}`;
|
|
656
|
+
}
|
|
657
|
+
break;
|
|
658
|
+
case 'DROP':
|
|
659
|
+
if (op.columnName) {
|
|
660
|
+
sql += ` DROP COLUMN ${this.escapeIdentifier(op.columnName)}`;
|
|
661
|
+
}
|
|
662
|
+
else if (op.constraintName) {
|
|
663
|
+
sql += ` DROP CONSTRAINT ${this.escapeIdentifier(op.constraintName)}`;
|
|
664
|
+
}
|
|
665
|
+
break;
|
|
666
|
+
case 'MODIFY':
|
|
667
|
+
if (op.column) {
|
|
668
|
+
// PostgreSQL uses ALTER COLUMN for modifications
|
|
669
|
+
const col = op.column;
|
|
670
|
+
if (col.type) {
|
|
671
|
+
sql += ` ALTER COLUMN ${this.escapeIdentifier(col.name)} TYPE ${this.getColumnTypeString(col.type, col)}`;
|
|
672
|
+
}
|
|
673
|
+
if (col.nullable !== undefined) {
|
|
674
|
+
if (col.nullable) {
|
|
675
|
+
sql += ` ALTER COLUMN ${this.escapeIdentifier(col.name)} DROP NOT NULL`;
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
sql += ` ALTER COLUMN ${this.escapeIdentifier(col.name)} SET NOT NULL`;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (col.defaultValue !== undefined) {
|
|
682
|
+
sql += ` ALTER COLUMN ${this.escapeIdentifier(col.name)} SET DEFAULT ${this.escapeValue(col.defaultValue)}`;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
break;
|
|
686
|
+
case 'RENAME':
|
|
687
|
+
if (op.oldName && op.newName) {
|
|
688
|
+
sql += ` RENAME COLUMN ${this.escapeIdentifier(op.oldName)} TO ${this.escapeIdentifier(op.newName)}`;
|
|
689
|
+
}
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
await this.pool.query(sql);
|
|
693
|
+
}
|
|
607
694
|
}
|
|
608
695
|
catch (error) {
|
|
609
|
-
|
|
610
|
-
success: false,
|
|
611
|
-
operation: 'drop',
|
|
612
|
-
indexName: options.indexName,
|
|
613
|
-
table: options.table,
|
|
614
|
-
error: error.message,
|
|
615
|
-
executionTime: Date.now() - startTime,
|
|
616
|
-
};
|
|
696
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to alter table: ${error.message}`, error);
|
|
617
697
|
}
|
|
618
698
|
}
|
|
619
|
-
async
|
|
699
|
+
async dropTable(tableName, ifExists, cascade) {
|
|
700
|
+
this.ensureConnected();
|
|
620
701
|
try {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
FROM
|
|
629
|
-
pg_class t,
|
|
630
|
-
pg_class i,
|
|
631
|
-
pg_index ix,
|
|
632
|
-
pg_attribute a,
|
|
633
|
-
pg_am am
|
|
634
|
-
WHERE
|
|
635
|
-
t.oid = ix.indrelid
|
|
636
|
-
AND i.oid = ix.indexrelid
|
|
637
|
-
AND a.attrelid = t.oid
|
|
638
|
-
AND a.attnum = ANY(ix.indkey)
|
|
639
|
-
AND t.relkind = 'r'
|
|
640
|
-
AND t.relname = $1
|
|
641
|
-
AND i.relam = am.oid
|
|
642
|
-
ORDER BY
|
|
643
|
-
i.relname,
|
|
644
|
-
a.attnum
|
|
645
|
-
`;
|
|
646
|
-
const result = await client.query(query, [options.table]);
|
|
647
|
-
// Group by index name
|
|
648
|
-
const indexMap = new Map();
|
|
649
|
-
result.rows.forEach((row) => {
|
|
650
|
-
if (!indexMap.has(row.index_name)) {
|
|
651
|
-
indexMap.set(row.index_name, {
|
|
652
|
-
name: row.index_name,
|
|
653
|
-
table: options.table,
|
|
654
|
-
columns: [],
|
|
655
|
-
columnDetails: [],
|
|
656
|
-
unique: row.is_unique,
|
|
657
|
-
primaryKey: false,
|
|
658
|
-
type: row.index_type,
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
const indexInfo = indexMap.get(row.index_name);
|
|
662
|
-
indexInfo.columns.push(row.column_name);
|
|
663
|
-
indexInfo.columnDetails.push({
|
|
664
|
-
name: row.column_name,
|
|
665
|
-
order: 'ASC',
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
return Array.from(indexMap.values());
|
|
702
|
+
let sql = 'DROP TABLE';
|
|
703
|
+
if (ifExists)
|
|
704
|
+
sql += ' IF EXISTS';
|
|
705
|
+
sql += ` ${this.escapeIdentifier(tableName)}`;
|
|
706
|
+
if (cascade)
|
|
707
|
+
sql += ' CASCADE';
|
|
708
|
+
await this.pool.query(sql);
|
|
669
709
|
}
|
|
670
710
|
catch (error) {
|
|
671
|
-
throw
|
|
711
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to drop table: ${error.message}`, error);
|
|
672
712
|
}
|
|
673
713
|
}
|
|
674
|
-
async
|
|
714
|
+
async listTables() {
|
|
715
|
+
this.ensureConnected();
|
|
675
716
|
try {
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
idx_scan as scans,
|
|
683
|
-
idx_tup_read as tuples_read,
|
|
684
|
-
idx_tup_fetch as tuples_fetched
|
|
685
|
-
FROM
|
|
686
|
-
pg_stat_user_indexes
|
|
687
|
-
WHERE
|
|
688
|
-
tablename = $1
|
|
689
|
-
`;
|
|
690
|
-
const params = [tableName];
|
|
691
|
-
if (indexName) {
|
|
692
|
-
query += ` AND indexname = $2`;
|
|
693
|
-
params.push(indexName);
|
|
694
|
-
}
|
|
695
|
-
const result = await client.query(query, params);
|
|
696
|
-
return result.rows.map((row) => ({
|
|
697
|
-
indexName: row.indexname,
|
|
698
|
-
tableName: row.tablename,
|
|
699
|
-
scans: row.scans,
|
|
700
|
-
tuplesRead: row.tuples_read,
|
|
701
|
-
tuplesFetched: row.tuples_fetched,
|
|
702
|
-
}));
|
|
717
|
+
const result = await this.pool.query(`
|
|
718
|
+
SELECT tablename FROM pg_tables
|
|
719
|
+
WHERE schemaname = 'public'
|
|
720
|
+
ORDER BY tablename
|
|
721
|
+
`);
|
|
722
|
+
return result.rows.map((r) => r.tablename);
|
|
703
723
|
}
|
|
704
724
|
catch (error) {
|
|
705
|
-
throw
|
|
725
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to list tables: ${error.message}`, error);
|
|
706
726
|
}
|
|
707
727
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
* Build SQL for a migration operation
|
|
711
|
-
*/
|
|
712
|
-
async buildMigrationOperationSQL(operation) {
|
|
713
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
714
|
-
switch (operation.type) {
|
|
715
|
-
case migration_types_1.MigrationOperationType.RAW_SQL:
|
|
716
|
-
return operation.sql || null;
|
|
717
|
-
case migration_types_1.MigrationOperationType.CREATE_TABLE:
|
|
718
|
-
if ((_a = operation.params) === null || _a === void 0 ? void 0 : _a.schema) {
|
|
719
|
-
const schema = operation.params.schema;
|
|
720
|
-
const columns = schema.columns
|
|
721
|
-
.map((col) => {
|
|
722
|
-
let def = `"${col.name}" ${this.mapColumnTypeToPostgreSQL(col.type)}`;
|
|
723
|
-
if (col.primaryKey)
|
|
724
|
-
def += ' PRIMARY KEY';
|
|
725
|
-
if (!col.nullable)
|
|
726
|
-
def += ' NOT NULL';
|
|
727
|
-
if (col.unique)
|
|
728
|
-
def += ' UNIQUE';
|
|
729
|
-
if (col.defaultValue !== undefined) {
|
|
730
|
-
def += ` DEFAULT ${this.escapeValue(col.defaultValue)}`;
|
|
731
|
-
}
|
|
732
|
-
return def;
|
|
733
|
-
})
|
|
734
|
-
.join(', ');
|
|
735
|
-
return `CREATE TABLE "${schema.name}" (${columns})`;
|
|
736
|
-
}
|
|
737
|
-
return null;
|
|
738
|
-
case migration_types_1.MigrationOperationType.DROP_TABLE:
|
|
739
|
-
return operation.table ? `DROP TABLE IF EXISTS "${operation.table}"` : null;
|
|
740
|
-
case migration_types_1.MigrationOperationType.ADD_COLUMN:
|
|
741
|
-
if (operation.table && ((_b = operation.params) === null || _b === void 0 ? void 0 : _b.column)) {
|
|
742
|
-
const col = operation.params.column;
|
|
743
|
-
let def = `ALTER TABLE "${operation.table}" ADD COLUMN "${col.name}" ${this.mapColumnTypeToPostgreSQL(col.type)}`;
|
|
744
|
-
if (!col.nullable)
|
|
745
|
-
def += ' NOT NULL';
|
|
746
|
-
if (col.defaultValue !== undefined) {
|
|
747
|
-
def += ` DEFAULT ${this.escapeValue(col.defaultValue)}`;
|
|
748
|
-
}
|
|
749
|
-
return def;
|
|
750
|
-
}
|
|
751
|
-
return null;
|
|
752
|
-
case migration_types_1.MigrationOperationType.DROP_COLUMN:
|
|
753
|
-
return operation.table && ((_c = operation.params) === null || _c === void 0 ? void 0 : _c.columnName)
|
|
754
|
-
? `ALTER TABLE "${operation.table}" DROP COLUMN "${operation.params.columnName}"`
|
|
755
|
-
: null;
|
|
756
|
-
case migration_types_1.MigrationOperationType.MODIFY_COLUMN:
|
|
757
|
-
if (operation.table && ((_d = operation.params) === null || _d === void 0 ? void 0 : _d.column)) {
|
|
758
|
-
const col = operation.params.column;
|
|
759
|
-
return `ALTER TABLE "${operation.table}" ALTER COLUMN "${col.name}" TYPE ${this.mapColumnTypeToPostgreSQL(col.type)}`;
|
|
760
|
-
}
|
|
761
|
-
return null;
|
|
762
|
-
case migration_types_1.MigrationOperationType.RENAME_COLUMN:
|
|
763
|
-
return operation.table && ((_e = operation.params) === null || _e === void 0 ? void 0 : _e.oldName) && ((_f = operation.params) === null || _f === void 0 ? void 0 : _f.newName)
|
|
764
|
-
? `ALTER TABLE "${operation.table}" RENAME COLUMN "${operation.params.oldName}" TO "${operation.params.newName}"`
|
|
765
|
-
: null;
|
|
766
|
-
case migration_types_1.MigrationOperationType.ADD_INDEX:
|
|
767
|
-
if (operation.table && ((_g = operation.params) === null || _g === void 0 ? void 0 : _g.indexName) && ((_h = operation.params) === null || _h === void 0 ? void 0 : _h.columns)) {
|
|
768
|
-
const unique = operation.params.unique ? 'UNIQUE ' : '';
|
|
769
|
-
const columns = operation.params.columns.map((col) => `"${col}"`).join(', ');
|
|
770
|
-
return `CREATE ${unique}INDEX "${operation.params.indexName}" ON "${operation.table}" (${columns})`;
|
|
771
|
-
}
|
|
772
|
-
return null;
|
|
773
|
-
case migration_types_1.MigrationOperationType.DROP_INDEX:
|
|
774
|
-
return ((_j = operation.params) === null || _j === void 0 ? void 0 : _j.indexName)
|
|
775
|
-
? `DROP INDEX IF EXISTS "${operation.params.indexName}"`
|
|
776
|
-
: null;
|
|
777
|
-
case migration_types_1.MigrationOperationType.ADD_CONSTRAINT:
|
|
778
|
-
if (operation.table && ((_k = operation.params) === null || _k === void 0 ? void 0 : _k.constraintName) && ((_l = operation.params) === null || _l === void 0 ? void 0 : _l.definition)) {
|
|
779
|
-
return `ALTER TABLE "${operation.table}" ADD CONSTRAINT "${operation.params.constraintName}" ${operation.params.definition}`;
|
|
780
|
-
}
|
|
781
|
-
return null;
|
|
782
|
-
case migration_types_1.MigrationOperationType.DROP_CONSTRAINT:
|
|
783
|
-
return operation.table && ((_m = operation.params) === null || _m === void 0 ? void 0 : _m.constraintName)
|
|
784
|
-
? `ALTER TABLE "${operation.table}" DROP CONSTRAINT IF EXISTS "${operation.params.constraintName}"`
|
|
785
|
-
: null;
|
|
786
|
-
default:
|
|
787
|
-
return null;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
async runMigration(connection, migration, options) {
|
|
791
|
-
const startTime = Date.now();
|
|
792
|
-
const statements = [];
|
|
728
|
+
async tableExists(tableName) {
|
|
729
|
+
this.ensureConnected();
|
|
793
730
|
try {
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
statements.push(sql);
|
|
802
|
-
await client.query(sql);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
// Record migration in history table
|
|
806
|
-
await this.recordMigration(client, migration, migration_types_1.MigrationDirection.UP);
|
|
807
|
-
await client.query('COMMIT');
|
|
808
|
-
return {
|
|
809
|
-
tag: migration.tag,
|
|
810
|
-
status: migration_types_1.MigrationStatus.COMPLETED,
|
|
811
|
-
direction: migration_types_1.MigrationDirection.UP,
|
|
812
|
-
executedAt: new Date(),
|
|
813
|
-
duration: Date.now() - startTime,
|
|
814
|
-
statements,
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
catch (error) {
|
|
818
|
-
await client.query('ROLLBACK');
|
|
819
|
-
throw error;
|
|
820
|
-
}
|
|
731
|
+
const result = await this.pool.query(`
|
|
732
|
+
SELECT EXISTS (
|
|
733
|
+
SELECT FROM pg_tables
|
|
734
|
+
WHERE schemaname = 'public' AND tablename = $1
|
|
735
|
+
)
|
|
736
|
+
`, [tableName]);
|
|
737
|
+
return result.rows[0].exists;
|
|
821
738
|
}
|
|
822
739
|
catch (error) {
|
|
740
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to check table existence: ${error.message}`, error);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
async getTableSchema(tableName) {
|
|
744
|
+
this.ensureConnected();
|
|
745
|
+
try {
|
|
746
|
+
// Get columns
|
|
747
|
+
const columnsResult = await this.pool.query(`
|
|
748
|
+
SELECT
|
|
749
|
+
column_name as name,
|
|
750
|
+
data_type as type,
|
|
751
|
+
is_nullable = 'YES' as nullable,
|
|
752
|
+
column_default as default_value,
|
|
753
|
+
character_maximum_length as max_length,
|
|
754
|
+
numeric_precision as precision,
|
|
755
|
+
numeric_scale as scale
|
|
756
|
+
FROM information_schema.columns
|
|
757
|
+
WHERE table_schema = 'public' AND table_name = $1
|
|
758
|
+
ORDER BY ordinal_position
|
|
759
|
+
`, [tableName]);
|
|
760
|
+
// Get primary key
|
|
761
|
+
const pkResult = await this.pool.query(`
|
|
762
|
+
SELECT a.attname as column_name
|
|
763
|
+
FROM pg_index i
|
|
764
|
+
JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
|
|
765
|
+
WHERE i.indrelid = $1::regclass AND i.indisprimary
|
|
766
|
+
`, [tableName]);
|
|
767
|
+
const primaryKey = pkResult.rows.map((r) => r.column_name);
|
|
768
|
+
// Get indexes
|
|
769
|
+
const indexes = await this.listIndexes(tableName);
|
|
770
|
+
// Get constraints
|
|
771
|
+
const constraintsResult = await this.pool.query(`
|
|
772
|
+
SELECT
|
|
773
|
+
con.conname as name,
|
|
774
|
+
CASE con.contype
|
|
775
|
+
WHEN 'p' THEN 'PRIMARY KEY'
|
|
776
|
+
WHEN 'f' THEN 'FOREIGN KEY'
|
|
777
|
+
WHEN 'u' THEN 'UNIQUE'
|
|
778
|
+
WHEN 'c' THEN 'CHECK'
|
|
779
|
+
END as type,
|
|
780
|
+
ARRAY(
|
|
781
|
+
SELECT a.attname
|
|
782
|
+
FROM unnest(con.conkey) WITH ORDINALITY AS k(key, ord)
|
|
783
|
+
JOIN pg_attribute a ON a.attnum = k.key AND a.attrelid = con.conrelid
|
|
784
|
+
ORDER BY k.ord
|
|
785
|
+
) as columns,
|
|
786
|
+
pg_get_constraintdef(con.oid) as definition
|
|
787
|
+
FROM pg_constraint con
|
|
788
|
+
JOIN pg_namespace nsp ON nsp.oid = con.connamespace
|
|
789
|
+
WHERE con.conrelid = $1::regclass AND nsp.nspname = 'public'
|
|
790
|
+
`, [tableName]);
|
|
791
|
+
const columns = columnsResult.rows.map((col) => {
|
|
792
|
+
var _a;
|
|
793
|
+
return ({
|
|
794
|
+
name: col.name,
|
|
795
|
+
type: col.type,
|
|
796
|
+
nullable: col.nullable,
|
|
797
|
+
defaultValue: col.default_value,
|
|
798
|
+
isPrimaryKey: primaryKey.includes(col.name),
|
|
799
|
+
isUnique: false, // Would need additional query
|
|
800
|
+
isAutoIncrement: (_a = col.default_value) === null || _a === void 0 ? void 0 : _a.includes('nextval'),
|
|
801
|
+
maxLength: col.max_length,
|
|
802
|
+
precision: col.precision,
|
|
803
|
+
scale: col.scale,
|
|
804
|
+
});
|
|
805
|
+
});
|
|
806
|
+
const constraints = constraintsResult.rows.map((c) => ({
|
|
807
|
+
name: c.name,
|
|
808
|
+
type: c.type,
|
|
809
|
+
columns: c.columns,
|
|
810
|
+
expression: c.definition,
|
|
811
|
+
}));
|
|
823
812
|
return {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
statements,
|
|
813
|
+
name: tableName,
|
|
814
|
+
schema: 'public',
|
|
815
|
+
columns,
|
|
816
|
+
indexes,
|
|
817
|
+
constraints,
|
|
818
|
+
primaryKey: primaryKey.length > 0 ? primaryKey : undefined,
|
|
831
819
|
};
|
|
832
820
|
}
|
|
821
|
+
catch (error) {
|
|
822
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to get table schema: ${error.message}`, error);
|
|
823
|
+
}
|
|
833
824
|
}
|
|
834
|
-
async
|
|
835
|
-
|
|
836
|
-
const statements = [];
|
|
825
|
+
async createIndex(index, ifNotExists, concurrent) {
|
|
826
|
+
this.ensureConnected();
|
|
837
827
|
try {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
828
|
+
let sql = 'CREATE';
|
|
829
|
+
if (index.unique)
|
|
830
|
+
sql += ' UNIQUE';
|
|
831
|
+
sql += ' INDEX';
|
|
832
|
+
if (concurrent)
|
|
833
|
+
sql += ' CONCURRENTLY';
|
|
834
|
+
if (ifNotExists)
|
|
835
|
+
sql += ' IF NOT EXISTS';
|
|
836
|
+
sql += ` ${this.escapeIdentifier(index.name)} ON ${this.escapeIdentifier(index.table)}`;
|
|
837
|
+
// Add index method
|
|
838
|
+
if (index.method) {
|
|
839
|
+
sql += ` USING ${index.method}`;
|
|
840
|
+
}
|
|
841
|
+
// Add columns
|
|
842
|
+
const columnDefs = index.columns.map(col => {
|
|
843
|
+
let def = this.escapeIdentifier(col.name);
|
|
844
|
+
if (col.order)
|
|
845
|
+
def += ` ${col.order}`;
|
|
846
|
+
if (col.nulls)
|
|
847
|
+
def += ` NULLS ${col.nulls}`;
|
|
848
|
+
if (col.opclass)
|
|
849
|
+
def += ` ${col.opclass}`;
|
|
850
|
+
return def;
|
|
851
|
+
}).join(', ');
|
|
852
|
+
sql += ` (${columnDefs})`;
|
|
853
|
+
// Add include columns (covering index)
|
|
854
|
+
if (index.include && index.include.length > 0) {
|
|
855
|
+
sql += ` INCLUDE (${index.include.map(c => this.escapeIdentifier(c)).join(', ')})`;
|
|
860
856
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
857
|
+
// Add partial index condition
|
|
858
|
+
if (index.where) {
|
|
859
|
+
sql += ` WHERE ${index.where}`;
|
|
860
|
+
}
|
|
861
|
+
await this.pool.query(sql);
|
|
862
|
+
// Add comment
|
|
863
|
+
if (index.comment) {
|
|
864
|
+
await this.pool.query(`COMMENT ON INDEX ${this.escapeIdentifier(index.name)} IS ${this.escapeValue(index.comment)}`);
|
|
864
865
|
}
|
|
865
866
|
}
|
|
866
867
|
catch (error) {
|
|
867
|
-
|
|
868
|
-
tag: migration.tag,
|
|
869
|
-
status: migration_types_1.MigrationStatus.FAILED,
|
|
870
|
-
direction: migration_types_1.MigrationDirection.DOWN,
|
|
871
|
-
executedAt: new Date(),
|
|
872
|
-
duration: Date.now() - startTime,
|
|
873
|
-
error: error.message,
|
|
874
|
-
statements,
|
|
875
|
-
};
|
|
868
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to create index: ${error.message}`, error);
|
|
876
869
|
}
|
|
877
870
|
}
|
|
878
|
-
async
|
|
871
|
+
async dropIndex(tableName, indexName, ifExists, concurrent, cascade) {
|
|
872
|
+
this.ensureConnected();
|
|
879
873
|
try {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
874
|
+
let sql = 'DROP INDEX';
|
|
875
|
+
if (concurrent)
|
|
876
|
+
sql += ' CONCURRENTLY';
|
|
877
|
+
if (ifExists)
|
|
878
|
+
sql += ' IF EXISTS';
|
|
879
|
+
sql += ` ${this.escapeIdentifier(indexName)}`;
|
|
880
|
+
if (cascade)
|
|
881
|
+
sql += ' CASCADE';
|
|
882
|
+
await this.pool.query(sql);
|
|
883
|
+
}
|
|
884
|
+
catch (error) {
|
|
885
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to drop index: ${error.message}`, error);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
async listIndexes(tableName, includeSystem) {
|
|
889
|
+
this.ensureConnected();
|
|
890
|
+
try {
|
|
891
|
+
let sql = `
|
|
892
|
+
SELECT
|
|
893
|
+
i.relname as name,
|
|
894
|
+
t.relname as table,
|
|
895
|
+
ARRAY(
|
|
896
|
+
SELECT a.attname
|
|
897
|
+
FROM unnest(ix.indkey) WITH ORDINALITY AS k(key, ord)
|
|
898
|
+
JOIN pg_attribute a ON a.attnum = k.key AND a.attrelid = ix.indrelid
|
|
899
|
+
ORDER BY k.ord
|
|
900
|
+
) as columns,
|
|
901
|
+
ix.indisunique as unique,
|
|
902
|
+
ix.indisprimary as primary_key,
|
|
903
|
+
am.amname as type,
|
|
904
|
+
pg_relation_size(i.oid) as size,
|
|
905
|
+
pg_get_indexdef(ix.indexrelid) as definition
|
|
906
|
+
FROM pg_index ix
|
|
907
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
908
|
+
JOIN pg_class t ON t.oid = ix.indrelid
|
|
909
|
+
JOIN pg_am am ON am.oid = i.relam
|
|
910
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
911
|
+
WHERE t.relname = $1 AND n.nspname = 'public'
|
|
887
912
|
`;
|
|
888
|
-
|
|
913
|
+
if (!includeSystem) {
|
|
914
|
+
sql += ` AND NOT i.relname LIKE 'pg_%'`;
|
|
915
|
+
}
|
|
916
|
+
const result = await this.pool.query(sql, [tableName]);
|
|
889
917
|
return result.rows.map((row) => ({
|
|
890
|
-
tag: row.tag,
|
|
891
918
|
name: row.name,
|
|
892
|
-
|
|
919
|
+
table: row.table,
|
|
920
|
+
columns: row.columns,
|
|
921
|
+
unique: row.unique,
|
|
922
|
+
primaryKey: row.primary_key,
|
|
923
|
+
type: row.type,
|
|
924
|
+
size: parseInt(row.size, 10),
|
|
893
925
|
}));
|
|
894
926
|
}
|
|
895
927
|
catch (error) {
|
|
896
|
-
throw
|
|
928
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to list indexes: ${error.message}`, error);
|
|
897
929
|
}
|
|
898
930
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
// Add included relation columns
|
|
919
|
-
if (hasIncludes) {
|
|
920
|
-
const includes = Array.isArray(options.include) ? options.include : [options.include];
|
|
921
|
-
includes.forEach((include) => {
|
|
922
|
-
const relationAlias = include.relation;
|
|
923
|
-
if (include.select && include.select.length > 0) {
|
|
924
|
-
const relationCols = include.select.map((col) => `"${relationAlias}"."${col}" as "${relationAlias}_${col}"`).join(', ');
|
|
925
|
-
selectColumns += `, ${relationCols}`;
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
928
|
-
// Use JSON aggregation for one-to-many
|
|
929
|
-
if (include.type === 'one-to-many') {
|
|
930
|
-
selectColumns += `, json_agg("${relationAlias}".*) as "${relationAlias}"`;
|
|
931
|
-
}
|
|
932
|
-
else {
|
|
933
|
-
selectColumns += `, row_to_json("${relationAlias}".*) as "${relationAlias}"`;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
let query = `SELECT ${options.distinct ? 'DISTINCT ' : ''}${selectColumns} FROM "${options.table}"`;
|
|
939
|
-
// JOIN clauses for includes
|
|
940
|
-
if (hasIncludes) {
|
|
941
|
-
const includes = Array.isArray(options.include) ? options.include : [options.include];
|
|
942
|
-
includes.forEach((include) => {
|
|
943
|
-
const { joinClause } = this.buildIncludeJoin(options.table, include);
|
|
944
|
-
query += ` ${joinClause}`;
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
// WHERE clause
|
|
948
|
-
if (options.where) {
|
|
949
|
-
const { clause, values } = this.buildWhereClause(options.where, paramIndex);
|
|
950
|
-
query += ` WHERE ${clause}`;
|
|
951
|
-
params.push(...values);
|
|
952
|
-
paramIndex += values.length;
|
|
953
|
-
}
|
|
954
|
-
// GROUP BY clause
|
|
955
|
-
if (options.groupBy && options.groupBy.length > 0) {
|
|
956
|
-
query += ` GROUP BY ${options.groupBy.map((col) => `"${col}"`).join(', ')}`;
|
|
957
|
-
}
|
|
958
|
-
else if (hasIncludes) {
|
|
959
|
-
// Auto group by main table primary key for one-to-many relations
|
|
960
|
-
const includes = Array.isArray(options.include) ? options.include : [options.include];
|
|
961
|
-
const hasOneToMany = includes.some(inc => inc.type === 'one-to-many');
|
|
962
|
-
if (hasOneToMany) {
|
|
963
|
-
query += ` GROUP BY "${options.table}"."id"`;
|
|
931
|
+
async getIndexStatistics(tableName, indexName) {
|
|
932
|
+
this.ensureConnected();
|
|
933
|
+
try {
|
|
934
|
+
let sql = `
|
|
935
|
+
SELECT
|
|
936
|
+
indexrelname as index_name,
|
|
937
|
+
relname as table_name,
|
|
938
|
+
idx_scan as scans,
|
|
939
|
+
idx_tup_read as tuples_read,
|
|
940
|
+
idx_tup_fetch as tuples_fetched,
|
|
941
|
+
pg_relation_size(indexrelid) as size_bytes,
|
|
942
|
+
pg_size_pretty(pg_relation_size(indexrelid)) as size_formatted
|
|
943
|
+
FROM pg_stat_user_indexes
|
|
944
|
+
WHERE relname = $1
|
|
945
|
+
`;
|
|
946
|
+
const params = [tableName];
|
|
947
|
+
if (indexName) {
|
|
948
|
+
sql += ` AND indexrelname = $2`;
|
|
949
|
+
params.push(indexName);
|
|
964
950
|
}
|
|
951
|
+
const result = await this.pool.query(sql, params);
|
|
952
|
+
return result.rows.map((row) => ({
|
|
953
|
+
indexName: row.index_name,
|
|
954
|
+
tableName: row.table_name,
|
|
955
|
+
scans: parseInt(row.scans, 10),
|
|
956
|
+
tuplesRead: parseInt(row.tuples_read, 10),
|
|
957
|
+
tuplesFetched: parseInt(row.tuples_fetched, 10),
|
|
958
|
+
sizeBytes: parseInt(row.size_bytes, 10),
|
|
959
|
+
sizeFormatted: row.size_formatted,
|
|
960
|
+
}));
|
|
961
|
+
}
|
|
962
|
+
catch (error) {
|
|
963
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to get index statistics: ${error.message}`, error);
|
|
965
964
|
}
|
|
966
|
-
// HAVING clause
|
|
967
|
-
if (options.having) {
|
|
968
|
-
const { clause, values } = this.buildWhereClause(options.having, paramIndex);
|
|
969
|
-
query += ` HAVING ${clause}`;
|
|
970
|
-
params.push(...values);
|
|
971
|
-
paramIndex += values.length;
|
|
972
|
-
}
|
|
973
|
-
// ORDER BY clause
|
|
974
|
-
if (options.orderBy) {
|
|
975
|
-
const orderByArray = Array.isArray(options.orderBy) ? options.orderBy : [options.orderBy];
|
|
976
|
-
const orderClauses = orderByArray.map((order) => `"${options.table}"."${order.column}" ${order.order || 'ASC'}`);
|
|
977
|
-
query += ` ORDER BY ${orderClauses.join(', ')}`;
|
|
978
|
-
}
|
|
979
|
-
// LIMIT clause
|
|
980
|
-
if (options.limit) {
|
|
981
|
-
query += ` LIMIT $${paramIndex++}`;
|
|
982
|
-
params.push(options.limit);
|
|
983
|
-
}
|
|
984
|
-
// OFFSET clause
|
|
985
|
-
if (options.offset) {
|
|
986
|
-
query += ` OFFSET $${paramIndex++}`;
|
|
987
|
-
params.push(options.offset);
|
|
988
|
-
}
|
|
989
|
-
return { query, params };
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Build JOIN clause for include relationships
|
|
993
|
-
*/
|
|
994
|
-
buildIncludeJoin(mainTable, include) {
|
|
995
|
-
const relationTable = include.relation;
|
|
996
|
-
const foreignKey = include.foreignKey || `${relationTable}_id`;
|
|
997
|
-
const primaryKey = include.primaryKey || 'id';
|
|
998
|
-
const joinType = include.type === 'one-to-many' || include.type === 'one-to-one' ? 'LEFT' : 'INNER';
|
|
999
|
-
let joinClause;
|
|
1000
|
-
if (include.type === 'many-to-many' && include.through) {
|
|
1001
|
-
// Many-to-many with junction table
|
|
1002
|
-
const throughTable = include.through;
|
|
1003
|
-
const throughForeignKey = include.throughForeignKey || `${mainTable}_id`;
|
|
1004
|
-
const throughRelatedKey = include.throughRelatedKey || `${relationTable}_id`;
|
|
1005
|
-
joinClause = `${joinType} JOIN "${throughTable}" ON "${mainTable}"."${primaryKey}" = "${throughTable}"."${throughForeignKey}" `;
|
|
1006
|
-
joinClause += `${joinType} JOIN "${relationTable}" ON "${throughTable}"."${throughRelatedKey}" = "${relationTable}"."${primaryKey}"`;
|
|
1007
|
-
}
|
|
1008
|
-
else if (include.type === 'one-to-many') {
|
|
1009
|
-
// One-to-many: foreign key is in the related table
|
|
1010
|
-
joinClause = `${joinType} JOIN "${relationTable}" ON "${mainTable}"."${primaryKey}" = "${relationTable}"."${foreignKey}"`;
|
|
1011
|
-
}
|
|
1012
|
-
else {
|
|
1013
|
-
// Many-to-one or one-to-one: foreign key is in the main table
|
|
1014
|
-
joinClause = `${joinType} JOIN "${relationTable}" ON "${mainTable}"."${foreignKey}" = "${relationTable}"."${primaryKey}"`;
|
|
1015
|
-
}
|
|
1016
|
-
// Add where clause for the relation if specified
|
|
1017
|
-
if (include.where) {
|
|
1018
|
-
const { clause } = this.buildWhereClause(include.where, 1);
|
|
1019
|
-
joinClause += ` AND ${clause}`;
|
|
1020
|
-
}
|
|
1021
|
-
return { joinClause };
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Build INSERT query from options
|
|
1025
|
-
*/
|
|
1026
|
-
buildInsertQuery(options) {
|
|
1027
|
-
const dataArray = Array.isArray(options.data) ? options.data : [options.data];
|
|
1028
|
-
const columns = Object.keys(dataArray[0]);
|
|
1029
|
-
const params = [];
|
|
1030
|
-
let paramIndex = 1;
|
|
1031
|
-
let query = `INSERT INTO "${options.table}" (${columns.map((col) => `"${col}"`).join(', ')}) VALUES `;
|
|
1032
|
-
const valuesClauses = [];
|
|
1033
|
-
dataArray.forEach((data) => {
|
|
1034
|
-
const valuePlaceholders = columns.map(() => `$${paramIndex++}`);
|
|
1035
|
-
valuesClauses.push(`(${valuePlaceholders.join(', ')})`);
|
|
1036
|
-
params.push(...columns.map((col) => data[col]));
|
|
1037
|
-
});
|
|
1038
|
-
query += valuesClauses.join(', ');
|
|
1039
|
-
if (options.returning) {
|
|
1040
|
-
const returningColumns = Array.isArray(options.returning)
|
|
1041
|
-
? options.returning.map((col) => `"${col}"`).join(', ')
|
|
1042
|
-
: '*';
|
|
1043
|
-
query += ` RETURNING ${returningColumns}`;
|
|
1044
|
-
}
|
|
1045
|
-
return { query, params };
|
|
1046
|
-
}
|
|
1047
|
-
/**
|
|
1048
|
-
* Build UPDATE query from options
|
|
1049
|
-
*/
|
|
1050
|
-
buildUpdateQuery(options) {
|
|
1051
|
-
const params = [];
|
|
1052
|
-
let paramIndex = 1;
|
|
1053
|
-
const setClauses = Object.keys(options.data).map((key) => {
|
|
1054
|
-
params.push(options.data[key]);
|
|
1055
|
-
return `"${key}" = $${paramIndex++}`;
|
|
1056
|
-
});
|
|
1057
|
-
let query = `UPDATE "${options.table}" SET ${setClauses.join(', ')}`;
|
|
1058
|
-
if (options.where) {
|
|
1059
|
-
const { clause, values } = this.buildWhereClause(options.where, paramIndex);
|
|
1060
|
-
query += ` WHERE ${clause}`;
|
|
1061
|
-
params.push(...values);
|
|
1062
|
-
}
|
|
1063
|
-
if (options.returning) {
|
|
1064
|
-
const returningColumns = Array.isArray(options.returning)
|
|
1065
|
-
? options.returning.map((col) => `"${col}"`).join(', ')
|
|
1066
|
-
: '*';
|
|
1067
|
-
query += ` RETURNING ${returningColumns}`;
|
|
1068
|
-
}
|
|
1069
|
-
return { query, params };
|
|
1070
965
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
const params = [];
|
|
1076
|
-
let paramIndex = 1;
|
|
1077
|
-
let query = `DELETE FROM "${options.table}"`;
|
|
1078
|
-
if (options.where) {
|
|
1079
|
-
const { clause, values } = this.buildWhereClause(options.where, paramIndex);
|
|
1080
|
-
query += ` WHERE ${clause}`;
|
|
1081
|
-
params.push(...values);
|
|
1082
|
-
}
|
|
1083
|
-
if (options.returning) {
|
|
1084
|
-
const returningColumns = Array.isArray(options.returning)
|
|
1085
|
-
? options.returning.map((col) => `"${col}"`).join(', ')
|
|
1086
|
-
: '*';
|
|
1087
|
-
query += ` RETURNING ${returningColumns}`;
|
|
1088
|
-
}
|
|
1089
|
-
return { query, params };
|
|
966
|
+
// ==================== UTILITY METHODS ====================
|
|
967
|
+
escapeIdentifier(identifier) {
|
|
968
|
+
// PostgreSQL uses double quotes for identifiers
|
|
969
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
1090
970
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
.
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
const returningColumns = Array.isArray(options.returning)
|
|
1110
|
-
? options.returning.map((col) => `"${col}"`).join(', ')
|
|
1111
|
-
: '*';
|
|
1112
|
-
query += ` RETURNING ${returningColumns}`;
|
|
1113
|
-
}
|
|
1114
|
-
return { query, params };
|
|
971
|
+
escapeValue(value) {
|
|
972
|
+
if (value === null || value === undefined) {
|
|
973
|
+
return 'NULL';
|
|
974
|
+
}
|
|
975
|
+
if (typeof value === 'number') {
|
|
976
|
+
return String(value);
|
|
977
|
+
}
|
|
978
|
+
if (typeof value === 'boolean') {
|
|
979
|
+
return value ? 'TRUE' : 'FALSE';
|
|
980
|
+
}
|
|
981
|
+
if (value instanceof Date) {
|
|
982
|
+
return `'${value.toISOString()}'`;
|
|
983
|
+
}
|
|
984
|
+
if (typeof value === 'object') {
|
|
985
|
+
return `'${JSON.stringify(value).replace(/'/g, "''")}'::jsonb`;
|
|
986
|
+
}
|
|
987
|
+
// String - escape single quotes
|
|
988
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
1115
989
|
}
|
|
1116
990
|
/**
|
|
1117
|
-
*
|
|
991
|
+
* Check if value is an update operator object
|
|
1118
992
|
*/
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
if (options.where) {
|
|
1125
|
-
const { clause, values } = this.buildWhereClause(options.where, paramIndex);
|
|
1126
|
-
query += ` WHERE ${clause}`;
|
|
1127
|
-
params.push(...values);
|
|
1128
|
-
}
|
|
1129
|
-
return { query, params };
|
|
993
|
+
isUpdateOperator(value) {
|
|
994
|
+
if (!value || typeof value !== 'object')
|
|
995
|
+
return false;
|
|
996
|
+
const operators = ['$INC', '$DEC', '$MUL', '$MIN', '$MAX', '$SET', '$UNSET', '$PUSH', '$PULL', '$ADDTOSET'];
|
|
997
|
+
return operators.some(op => op in value);
|
|
1130
998
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
buildAggregateQuery(func, column, options) {
|
|
1135
|
-
const params = [];
|
|
1136
|
-
let paramIndex = 1;
|
|
1137
|
-
let query = `SELECT ${func}("${column}") as result FROM "${options.table}"`;
|
|
1138
|
-
if (options.where) {
|
|
1139
|
-
const { clause, values } = this.buildWhereClause(options.where, paramIndex);
|
|
1140
|
-
query += ` WHERE ${clause}`;
|
|
1141
|
-
params.push(...values);
|
|
1142
|
-
}
|
|
1143
|
-
return { query, params };
|
|
999
|
+
getParameterPlaceholder(index) {
|
|
1000
|
+
// PostgreSQL uses $1, $2, $3, etc.
|
|
1001
|
+
return `$${index}`;
|
|
1144
1002
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1003
|
+
getColumnTypeString(columnType, options) {
|
|
1004
|
+
const typeMap = {
|
|
1005
|
+
[enums_1.ColumnType.INTEGER]: 'INTEGER',
|
|
1006
|
+
[enums_1.ColumnType.BIGINT]: 'BIGINT',
|
|
1007
|
+
[enums_1.ColumnType.SMALLINT]: 'SMALLINT',
|
|
1008
|
+
[enums_1.ColumnType.FLOAT]: 'REAL',
|
|
1009
|
+
[enums_1.ColumnType.DOUBLE]: 'DOUBLE PRECISION',
|
|
1010
|
+
[enums_1.ColumnType.DECIMAL]: (options === null || options === void 0 ? void 0 : options.precision)
|
|
1011
|
+
? `NUMERIC(${options.precision}${options.scale ? `, ${options.scale}` : ''})`
|
|
1012
|
+
: 'NUMERIC',
|
|
1013
|
+
[enums_1.ColumnType.STRING]: (options === null || options === void 0 ? void 0 : options.maxLength) ? `VARCHAR(${options.maxLength})` : 'VARCHAR(255)',
|
|
1014
|
+
[enums_1.ColumnType.TEXT]: 'TEXT',
|
|
1015
|
+
[enums_1.ColumnType.BOOLEAN]: 'BOOLEAN',
|
|
1016
|
+
[enums_1.ColumnType.DATE]: 'DATE',
|
|
1017
|
+
[enums_1.ColumnType.DATETIME]: 'TIMESTAMP',
|
|
1018
|
+
[enums_1.ColumnType.TIMESTAMP]: 'TIMESTAMP WITH TIME ZONE',
|
|
1019
|
+
[enums_1.ColumnType.TIME]: 'TIME',
|
|
1020
|
+
[enums_1.ColumnType.JSON]: 'JSON',
|
|
1021
|
+
[enums_1.ColumnType.JSONB]: 'JSONB',
|
|
1022
|
+
[enums_1.ColumnType.UUID]: 'UUID',
|
|
1023
|
+
[enums_1.ColumnType.BINARY]: 'BYTEA',
|
|
1024
|
+
// ENUM type - returns VARCHAR, CHECK constraint is added in buildColumnDefinition
|
|
1025
|
+
[enums_1.ColumnType.ENUM]: 'VARCHAR(255)',
|
|
1026
|
+
[enums_1.ColumnType.ARRAY]: (options === null || options === void 0 ? void 0 : options.arrayType) ? `${options.arrayType}[]` : 'TEXT[]',
|
|
1027
|
+
};
|
|
1028
|
+
return typeMap[columnType] || columnType;
|
|
1029
|
+
}
|
|
1030
|
+
getSupportedFeatures() {
|
|
1031
|
+
return [
|
|
1032
|
+
base_adapter_1.DatabaseFeature.TRANSACTIONS,
|
|
1033
|
+
base_adapter_1.DatabaseFeature.SAVEPOINTS,
|
|
1034
|
+
base_adapter_1.DatabaseFeature.JSONB,
|
|
1035
|
+
base_adapter_1.DatabaseFeature.JSON,
|
|
1036
|
+
base_adapter_1.DatabaseFeature.ARRAYS,
|
|
1037
|
+
base_adapter_1.DatabaseFeature.UUID,
|
|
1038
|
+
base_adapter_1.DatabaseFeature.FULLTEXT_SEARCH,
|
|
1039
|
+
base_adapter_1.DatabaseFeature.GIN_INDEX,
|
|
1040
|
+
base_adapter_1.DatabaseFeature.GIST_INDEX,
|
|
1041
|
+
base_adapter_1.DatabaseFeature.HASH_INDEX,
|
|
1042
|
+
base_adapter_1.DatabaseFeature.PARTIAL_INDEX,
|
|
1043
|
+
base_adapter_1.DatabaseFeature.COVERING_INDEX,
|
|
1044
|
+
base_adapter_1.DatabaseFeature.CONCURRENT_INDEX,
|
|
1045
|
+
base_adapter_1.DatabaseFeature.CTE,
|
|
1046
|
+
base_adapter_1.DatabaseFeature.WINDOW_FUNCTIONS,
|
|
1047
|
+
base_adapter_1.DatabaseFeature.RETURNING,
|
|
1048
|
+
base_adapter_1.DatabaseFeature.UPSERT,
|
|
1049
|
+
base_adapter_1.DatabaseFeature.FOREIGN_KEYS,
|
|
1050
|
+
base_adapter_1.DatabaseFeature.CHECK_CONSTRAINTS,
|
|
1051
|
+
base_adapter_1.DatabaseFeature.STORED_PROCEDURES,
|
|
1052
|
+
base_adapter_1.DatabaseFeature.VIEWS,
|
|
1053
|
+
base_adapter_1.DatabaseFeature.MATERIALIZED_VIEWS,
|
|
1054
|
+
base_adapter_1.DatabaseFeature.TRIGGERS,
|
|
1055
|
+
base_adapter_1.DatabaseFeature.SCHEMAS,
|
|
1056
|
+
base_adapter_1.DatabaseFeature.TABLE_INHERITANCE,
|
|
1057
|
+
base_adapter_1.DatabaseFeature.LIKE,
|
|
1058
|
+
base_adapter_1.DatabaseFeature.ILIKE,
|
|
1059
|
+
base_adapter_1.DatabaseFeature.REGEX,
|
|
1060
|
+
base_adapter_1.DatabaseFeature.BETWEEN,
|
|
1061
|
+
base_adapter_1.DatabaseFeature.ARRAY_CONTAINS,
|
|
1062
|
+
base_adapter_1.DatabaseFeature.LIMIT_OFFSET,
|
|
1063
|
+
];
|
|
1064
|
+
}
|
|
1065
|
+
parseError(error) {
|
|
1066
|
+
const code = error.code;
|
|
1067
|
+
let type = enums_1.DatabaseErrorType.UNKNOWN_ERROR;
|
|
1068
|
+
// Map PostgreSQL error codes
|
|
1069
|
+
switch (code) {
|
|
1070
|
+
case '23505':
|
|
1071
|
+
type = enums_1.DatabaseErrorType.UNIQUE_VIOLATION;
|
|
1072
|
+
break;
|
|
1073
|
+
case '23503':
|
|
1074
|
+
type = enums_1.DatabaseErrorType.FOREIGN_KEY_VIOLATION;
|
|
1075
|
+
break;
|
|
1076
|
+
case '23502':
|
|
1077
|
+
type = enums_1.DatabaseErrorType.NOT_NULL_VIOLATION;
|
|
1078
|
+
break;
|
|
1079
|
+
case '23514':
|
|
1080
|
+
type = enums_1.DatabaseErrorType.CHECK_VIOLATION;
|
|
1081
|
+
break;
|
|
1082
|
+
case '08000':
|
|
1083
|
+
case '08003':
|
|
1084
|
+
case '08006':
|
|
1085
|
+
type = enums_1.DatabaseErrorType.CONNECTION_ERROR;
|
|
1086
|
+
break;
|
|
1087
|
+
case '42P01':
|
|
1088
|
+
case '42703':
|
|
1089
|
+
type = enums_1.DatabaseErrorType.SCHEMA_ERROR;
|
|
1090
|
+
break;
|
|
1091
|
+
case '28000':
|
|
1092
|
+
case '28P01':
|
|
1093
|
+
type = enums_1.DatabaseErrorType.AUTHENTICATION_ERROR;
|
|
1094
|
+
break;
|
|
1095
|
+
default:
|
|
1096
|
+
if (code === null || code === void 0 ? void 0 : code.startsWith('42')) {
|
|
1097
|
+
type = enums_1.DatabaseErrorType.QUERY_ERROR;
|
|
1178
1098
|
}
|
|
1179
|
-
});
|
|
1180
1099
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1100
|
+
return {
|
|
1101
|
+
type,
|
|
1102
|
+
message: error.message || 'Unknown database error',
|
|
1103
|
+
code,
|
|
1104
|
+
details: {
|
|
1105
|
+
constraint: error.constraint,
|
|
1106
|
+
table: error.table,
|
|
1107
|
+
column: error.column,
|
|
1108
|
+
detail: error.detail,
|
|
1109
|
+
hint: error.hint,
|
|
1110
|
+
},
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
// ==================== PRIVATE HELPER METHODS ====================
|
|
1114
|
+
ensureConnected() {
|
|
1115
|
+
if (!this.connected || !this.pool) {
|
|
1116
|
+
throw new database_error_1.DatabaseError('Not connected to PostgreSQL database', enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
1193
1117
|
}
|
|
1194
|
-
return { query, params };
|
|
1195
1118
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
*/
|
|
1199
|
-
buildMultiAggregateQuery(options) {
|
|
1119
|
+
buildWhereClause(where, startIndex) {
|
|
1120
|
+
const clauses = [];
|
|
1200
1121
|
const params = [];
|
|
1201
|
-
let paramIndex = 1;
|
|
1202
|
-
const aggregations = Object.entries(options.operations).map(([alias, agg]) => {
|
|
1203
|
-
const aggObj = agg;
|
|
1204
|
-
if (aggObj.$COUNT !== undefined) {
|
|
1205
|
-
const column = aggObj.$COUNT === '*' ? '*' : `"${aggObj.$COUNT}"`;
|
|
1206
|
-
return `COUNT(${column}) AS "${alias}"`;
|
|
1207
|
-
}
|
|
1208
|
-
if (aggObj.$SUM !== undefined) {
|
|
1209
|
-
return `SUM("${aggObj.$SUM}") AS "${alias}"`;
|
|
1210
|
-
}
|
|
1211
|
-
if (aggObj.$AVG !== undefined) {
|
|
1212
|
-
return `AVG("${aggObj.$AVG}") AS "${alias}"`;
|
|
1213
|
-
}
|
|
1214
|
-
if (aggObj.$MIN !== undefined) {
|
|
1215
|
-
return `MIN("${aggObj.$MIN}") AS "${alias}"`;
|
|
1216
|
-
}
|
|
1217
|
-
if (aggObj.$MAX !== undefined) {
|
|
1218
|
-
return `MAX("${aggObj.$MAX}") AS "${alias}"`;
|
|
1219
|
-
}
|
|
1220
|
-
if (aggObj.$STRING_AGG !== undefined) {
|
|
1221
|
-
return `STRING_AGG("${aggObj.$STRING_AGG}", ', ') AS "${alias}"`;
|
|
1222
|
-
}
|
|
1223
|
-
if (aggObj.$ARRAY_AGG !== undefined) {
|
|
1224
|
-
return `ARRAY_AGG("${aggObj.$ARRAY_AGG}") AS "${alias}"`;
|
|
1225
|
-
}
|
|
1226
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.VALIDATION_ERROR, `Invalid aggregation operation for alias "${alias}". Use format: { $COUNT: '*' }, { $SUM: 'column' }, etc.`);
|
|
1227
|
-
});
|
|
1228
|
-
let query = `SELECT ${aggregations.join(', ')} FROM "${options.table}"`;
|
|
1229
|
-
if (options.where) {
|
|
1230
|
-
const { clause, values } = this.buildWhereClause(options.where, paramIndex);
|
|
1231
|
-
query += ` WHERE ${clause}`;
|
|
1232
|
-
params.push(...values);
|
|
1233
|
-
paramIndex += values.length;
|
|
1234
|
-
}
|
|
1235
|
-
if (options.groupBy && options.groupBy.length > 0) {
|
|
1236
|
-
const groupCols = options.groupBy.map(col => `"${col}"`).join(', ');
|
|
1237
|
-
query += ` GROUP BY ${groupCols}`;
|
|
1238
|
-
}
|
|
1239
|
-
if (options.having) {
|
|
1240
|
-
const { clause, values } = this.buildWhereClause(options.having, paramIndex);
|
|
1241
|
-
query += ` HAVING ${clause}`;
|
|
1242
|
-
params.push(...values);
|
|
1243
|
-
}
|
|
1244
|
-
return { query, params };
|
|
1245
|
-
}
|
|
1246
|
-
/**
|
|
1247
|
-
* Build WHERE clause from WhereClause object
|
|
1248
|
-
* Supports both simplified syntax (GT, LT, AND, OR) and legacy syntax ($gt, $lt, $and, $or)
|
|
1249
|
-
*/
|
|
1250
|
-
buildWhereClause(where, startIndex = 1) {
|
|
1251
|
-
const values = [];
|
|
1252
1122
|
let paramIndex = startIndex;
|
|
1253
|
-
const
|
|
1254
|
-
if (
|
|
1255
|
-
|
|
1256
|
-
|
|
1123
|
+
for (const [key, value] of Object.entries(where)) {
|
|
1124
|
+
if (key === '$AND') {
|
|
1125
|
+
const andResult = this.buildWhereClause(value, paramIndex);
|
|
1126
|
+
clauses.push(`(${andResult.whereClause})`);
|
|
1127
|
+
params.push(...andResult.whereParams);
|
|
1128
|
+
paramIndex += andResult.whereParams.length;
|
|
1257
1129
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
const
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
else {
|
|
1266
|
-
// Legacy syntax: { $and: [cond1, cond2] }
|
|
1267
|
-
const subConditions = andConditions.map(buildCondition);
|
|
1268
|
-
return `(${subConditions.join(' AND ')})`;
|
|
1130
|
+
else if (key === '$OR') {
|
|
1131
|
+
const orClauses = [];
|
|
1132
|
+
for (const [orKey, orValue] of Object.entries(value)) {
|
|
1133
|
+
const orResult = this.buildWhereClause({ [orKey]: orValue }, paramIndex);
|
|
1134
|
+
orClauses.push(orResult.whereClause);
|
|
1135
|
+
params.push(...orResult.whereParams);
|
|
1136
|
+
paramIndex += orResult.whereParams.length;
|
|
1269
1137
|
}
|
|
1138
|
+
clauses.push(`(${orClauses.join(' OR ')})`);
|
|
1270
1139
|
}
|
|
1271
|
-
if (
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1140
|
+
else if (value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
|
|
1141
|
+
// Handle operators
|
|
1142
|
+
for (const [op, opValue] of Object.entries(value)) {
|
|
1143
|
+
switch (op) {
|
|
1144
|
+
case '$EQ':
|
|
1145
|
+
clauses.push(`${this.escapeIdentifier(key)} = $${paramIndex}`);
|
|
1146
|
+
params.push(opValue);
|
|
1147
|
+
paramIndex++;
|
|
1148
|
+
break;
|
|
1149
|
+
case '$NE':
|
|
1150
|
+
case '$NOT':
|
|
1151
|
+
clauses.push(`${this.escapeIdentifier(key)} != $${paramIndex}`);
|
|
1152
|
+
params.push(opValue);
|
|
1153
|
+
paramIndex++;
|
|
1154
|
+
break;
|
|
1155
|
+
case '$GT':
|
|
1156
|
+
clauses.push(`${this.escapeIdentifier(key)} > $${paramIndex}`);
|
|
1157
|
+
params.push(opValue);
|
|
1158
|
+
paramIndex++;
|
|
1159
|
+
break;
|
|
1160
|
+
case '$GTE':
|
|
1161
|
+
clauses.push(`${this.escapeIdentifier(key)} >= $${paramIndex}`);
|
|
1162
|
+
params.push(opValue);
|
|
1163
|
+
paramIndex++;
|
|
1164
|
+
break;
|
|
1165
|
+
case '$LT':
|
|
1166
|
+
clauses.push(`${this.escapeIdentifier(key)} < $${paramIndex}`);
|
|
1167
|
+
params.push(opValue);
|
|
1168
|
+
paramIndex++;
|
|
1169
|
+
break;
|
|
1170
|
+
case '$LTE':
|
|
1171
|
+
clauses.push(`${this.escapeIdentifier(key)} <= $${paramIndex}`);
|
|
1172
|
+
params.push(opValue);
|
|
1173
|
+
paramIndex++;
|
|
1174
|
+
break;
|
|
1175
|
+
case '$IN':
|
|
1176
|
+
clauses.push(`${this.escapeIdentifier(key)} = ANY($${paramIndex})`);
|
|
1177
|
+
params.push(opValue);
|
|
1178
|
+
paramIndex++;
|
|
1179
|
+
break;
|
|
1180
|
+
case '$NOT_IN':
|
|
1181
|
+
clauses.push(`${this.escapeIdentifier(key)} != ALL($${paramIndex})`);
|
|
1182
|
+
params.push(opValue);
|
|
1183
|
+
paramIndex++;
|
|
1184
|
+
break;
|
|
1185
|
+
case '$LIKE':
|
|
1186
|
+
clauses.push(`${this.escapeIdentifier(key)} LIKE $${paramIndex}`);
|
|
1187
|
+
params.push(opValue);
|
|
1188
|
+
paramIndex++;
|
|
1189
|
+
break;
|
|
1190
|
+
case '$ILIKE':
|
|
1191
|
+
clauses.push(`${this.escapeIdentifier(key)} ILIKE $${paramIndex}`);
|
|
1192
|
+
params.push(opValue);
|
|
1193
|
+
paramIndex++;
|
|
1194
|
+
break;
|
|
1195
|
+
case '$IS_NULL':
|
|
1196
|
+
clauses.push(`${this.escapeIdentifier(key)} IS ${opValue ? 'NULL' : 'NOT NULL'}`);
|
|
1197
|
+
break;
|
|
1198
|
+
case '$IS_NOT_NULL':
|
|
1199
|
+
clauses.push(`${this.escapeIdentifier(key)} IS ${opValue ? 'NOT NULL' : 'NULL'}`);
|
|
1200
|
+
break;
|
|
1201
|
+
case '$BETWEEN':
|
|
1202
|
+
const [min, max] = opValue;
|
|
1203
|
+
clauses.push(`${this.escapeIdentifier(key)} BETWEEN $${paramIndex} AND $${paramIndex + 1}`);
|
|
1204
|
+
params.push(min, max);
|
|
1205
|
+
paramIndex += 2;
|
|
1206
|
+
break;
|
|
1207
|
+
case '$CONTAINS':
|
|
1208
|
+
clauses.push(`${this.escapeIdentifier(key)} @> $${paramIndex}`);
|
|
1209
|
+
params.push(opValue);
|
|
1210
|
+
paramIndex++;
|
|
1211
|
+
break;
|
|
1212
|
+
case '$CONTAINED_BY':
|
|
1213
|
+
clauses.push(`${this.escapeIdentifier(key)} <@ $${paramIndex}`);
|
|
1214
|
+
params.push(opValue);
|
|
1215
|
+
paramIndex++;
|
|
1216
|
+
break;
|
|
1217
|
+
case '$OVERLAPS':
|
|
1218
|
+
clauses.push(`${this.escapeIdentifier(key)} && $${paramIndex}`);
|
|
1219
|
+
params.push(opValue);
|
|
1220
|
+
paramIndex++;
|
|
1221
|
+
break;
|
|
1283
1222
|
}
|
|
1284
|
-
return `(${subClauses.join(' OR ')})`;
|
|
1285
|
-
}
|
|
1286
|
-
else {
|
|
1287
|
-
// Legacy syntax: { $or: [cond1, cond2] }
|
|
1288
|
-
const subConditions = orConditions.map(buildCondition);
|
|
1289
|
-
return `(${subConditions.join(' OR ')})`;
|
|
1290
1223
|
}
|
|
1291
1224
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
continue;
|
|
1298
|
-
}
|
|
1299
|
-
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
1300
|
-
// Handle comparison operators
|
|
1301
|
-
for (const [op, opValue] of Object.entries(value)) {
|
|
1302
|
-
switch (op) {
|
|
1303
|
-
// Preferred $-prefixed syntax
|
|
1304
|
-
case '$GT':
|
|
1305
|
-
case 'GT':
|
|
1306
|
-
case '$gt':
|
|
1307
|
-
values.push(opValue);
|
|
1308
|
-
conditions.push(`"${key}" > $${paramIndex++}`);
|
|
1309
|
-
break;
|
|
1310
|
-
case '$GTE':
|
|
1311
|
-
case 'GTE':
|
|
1312
|
-
case '$gte':
|
|
1313
|
-
values.push(opValue);
|
|
1314
|
-
conditions.push(`"${key}" >= $${paramIndex++}`);
|
|
1315
|
-
break;
|
|
1316
|
-
case '$LT':
|
|
1317
|
-
case 'LT':
|
|
1318
|
-
case '$lt':
|
|
1319
|
-
values.push(opValue);
|
|
1320
|
-
conditions.push(`"${key}" < $${paramIndex++}`);
|
|
1321
|
-
break;
|
|
1322
|
-
case '$LTE':
|
|
1323
|
-
case 'LTE':
|
|
1324
|
-
case '$lte':
|
|
1325
|
-
values.push(opValue);
|
|
1326
|
-
conditions.push(`"${key}" <= $${paramIndex++}`);
|
|
1327
|
-
break;
|
|
1328
|
-
case '$NE':
|
|
1329
|
-
case '$NOT':
|
|
1330
|
-
case 'NE':
|
|
1331
|
-
case 'NOT':
|
|
1332
|
-
case '$ne':
|
|
1333
|
-
values.push(opValue);
|
|
1334
|
-
conditions.push(`"${key}" != $${paramIndex++}`);
|
|
1335
|
-
break;
|
|
1336
|
-
case '$IN':
|
|
1337
|
-
case 'IN':
|
|
1338
|
-
case '$in':
|
|
1339
|
-
values.push(opValue);
|
|
1340
|
-
conditions.push(`"${key}" = ANY($${paramIndex++})`);
|
|
1341
|
-
break;
|
|
1342
|
-
case '$NOT_IN':
|
|
1343
|
-
case 'NOT_IN':
|
|
1344
|
-
case '$nin':
|
|
1345
|
-
values.push(opValue);
|
|
1346
|
-
conditions.push(`"${key}" != ANY($${paramIndex++})`);
|
|
1347
|
-
break;
|
|
1348
|
-
case '$LIKE':
|
|
1349
|
-
case 'LIKE':
|
|
1350
|
-
case '$like':
|
|
1351
|
-
values.push(opValue);
|
|
1352
|
-
conditions.push(`"${key}" LIKE $${paramIndex++}`);
|
|
1353
|
-
break;
|
|
1354
|
-
case '$ILIKE':
|
|
1355
|
-
case 'ILIKE':
|
|
1356
|
-
case '$ilike':
|
|
1357
|
-
values.push(opValue);
|
|
1358
|
-
conditions.push(`"${key}" ILIKE $${paramIndex++}`);
|
|
1359
|
-
break;
|
|
1360
|
-
case '$IS_NULL':
|
|
1361
|
-
case 'IS_NULL':
|
|
1362
|
-
case '$null':
|
|
1363
|
-
conditions.push(`"${key}" IS NULL`);
|
|
1364
|
-
break;
|
|
1365
|
-
case '$IS_NOT_NULL':
|
|
1366
|
-
case 'IS_NOT_NULL':
|
|
1367
|
-
case '$notNull':
|
|
1368
|
-
conditions.push(`"${key}" IS NOT NULL`);
|
|
1369
|
-
break;
|
|
1370
|
-
case '$BETWEEN':
|
|
1371
|
-
case 'BETWEEN':
|
|
1372
|
-
case '$between':
|
|
1373
|
-
if (Array.isArray(opValue) && opValue.length === 2) {
|
|
1374
|
-
values.push(opValue[0], opValue[1]);
|
|
1375
|
-
conditions.push(`"${key}" BETWEEN $${paramIndex++} AND $${paramIndex++}`);
|
|
1376
|
-
}
|
|
1377
|
-
break;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
else {
|
|
1382
|
-
// Simple equality
|
|
1383
|
-
values.push(value);
|
|
1384
|
-
conditions.push(`"${key}" = $${paramIndex++}`);
|
|
1385
|
-
}
|
|
1225
|
+
else {
|
|
1226
|
+
// Simple equality
|
|
1227
|
+
clauses.push(`${this.escapeIdentifier(key)} = $${paramIndex}`);
|
|
1228
|
+
params.push(value);
|
|
1229
|
+
paramIndex++;
|
|
1386
1230
|
}
|
|
1387
|
-
|
|
1231
|
+
}
|
|
1232
|
+
return {
|
|
1233
|
+
whereClause: clauses.join(' AND '),
|
|
1234
|
+
whereParams: params,
|
|
1388
1235
|
};
|
|
1389
|
-
const clause = buildCondition(where);
|
|
1390
|
-
return { clause, values };
|
|
1391
1236
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
const
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
}
|
|
1413
|
-
if (!col.nullable && !col.primaryKey) {
|
|
1414
|
-
def += ' NOT NULL';
|
|
1415
|
-
}
|
|
1416
|
-
if (col.defaultValue !== undefined) {
|
|
1417
|
-
def += ` DEFAULT ${col.defaultValue}`;
|
|
1418
|
-
}
|
|
1419
|
-
if (col.autoIncrement) {
|
|
1420
|
-
def = `"${col.name}" SERIAL PRIMARY KEY`;
|
|
1421
|
-
}
|
|
1237
|
+
buildCountQuery(query) {
|
|
1238
|
+
// Build a COUNT query from the original query
|
|
1239
|
+
const fromIndex = query.sql.toUpperCase().indexOf('FROM');
|
|
1240
|
+
const orderByIndex = query.sql.toUpperCase().indexOf('ORDER BY');
|
|
1241
|
+
const limitIndex = query.sql.toUpperCase().indexOf('LIMIT');
|
|
1242
|
+
let endIndex = query.sql.length;
|
|
1243
|
+
if (orderByIndex > 0)
|
|
1244
|
+
endIndex = Math.min(endIndex, orderByIndex);
|
|
1245
|
+
if (limitIndex > 0)
|
|
1246
|
+
endIndex = Math.min(endIndex, limitIndex);
|
|
1247
|
+
return `SELECT COUNT(*) as count ${query.sql.substring(fromIndex, endIndex)}`;
|
|
1248
|
+
}
|
|
1249
|
+
buildColumnDefinition(column) {
|
|
1250
|
+
let def = `${this.escapeIdentifier(column.name)} ${this.getColumnTypeString(column.type, column)}`;
|
|
1251
|
+
if (column.primaryKey) {
|
|
1252
|
+
def += ' PRIMARY KEY';
|
|
1253
|
+
}
|
|
1254
|
+
if (column.autoIncrement) {
|
|
1255
|
+
// PostgreSQL uses SERIAL/BIGSERIAL
|
|
1256
|
+
def = `${this.escapeIdentifier(column.name)} ${column.type === enums_1.ColumnType.BIGINT ? 'BIGSERIAL' : 'SERIAL'} PRIMARY KEY`;
|
|
1422
1257
|
return def;
|
|
1423
|
-
});
|
|
1424
|
-
let query = `CREATE TABLE ${(options === null || options === void 0 ? void 0 : options.ifNotExists) ? 'IF NOT EXISTS ' : ''}"${schema.name}" (${columnDefs.join(', ')})`;
|
|
1425
|
-
return query;
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Build ALTER TABLE queries
|
|
1429
|
-
*/
|
|
1430
|
-
buildAlterTableQueries(tableName, alterations) {
|
|
1431
|
-
return alterations.map((alt) => {
|
|
1432
|
-
let query = `ALTER TABLE "${tableName}" `;
|
|
1433
|
-
switch (alt.type) {
|
|
1434
|
-
case schema_types_1.ColumnAlterationType.ADD:
|
|
1435
|
-
query += `ADD COLUMN "${alt.column.name}" ${this.mapColumnTypeToPostgreSQL(alt.column.type)}`;
|
|
1436
|
-
if (!alt.column.nullable) {
|
|
1437
|
-
query += ' NOT NULL';
|
|
1438
|
-
}
|
|
1439
|
-
break;
|
|
1440
|
-
case schema_types_1.ColumnAlterationType.DROP:
|
|
1441
|
-
query += `DROP COLUMN "${alt.oldName}"`;
|
|
1442
|
-
break;
|
|
1443
|
-
case schema_types_1.ColumnAlterationType.MODIFY:
|
|
1444
|
-
query += `ALTER COLUMN "${alt.column.name}" TYPE ${this.mapColumnTypeToPostgreSQL(alt.column.type)}`;
|
|
1445
|
-
break;
|
|
1446
|
-
case schema_types_1.ColumnAlterationType.RENAME:
|
|
1447
|
-
query += `RENAME COLUMN "${alt.oldName}" TO "${alt.newName}"`;
|
|
1448
|
-
break;
|
|
1449
|
-
}
|
|
1450
|
-
return query;
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Build CREATE INDEX query
|
|
1455
|
-
*/
|
|
1456
|
-
buildCreateIndexQuery(options) {
|
|
1457
|
-
const unique = options.index.unique ? 'UNIQUE ' : '';
|
|
1458
|
-
const columns = options.index.columns.map((col) => `"${col.name}"`).join(', ');
|
|
1459
|
-
return `CREATE ${unique}INDEX ${options.ifNotExists ? 'IF NOT EXISTS ' : ''}"${options.index.name}" ON "${options.table}" (${columns})`;
|
|
1460
|
-
}
|
|
1461
|
-
/**
|
|
1462
|
-
* Map ColumnType to PostgreSQL type
|
|
1463
|
-
*/
|
|
1464
|
-
mapColumnTypeToPostgreSQL(type) {
|
|
1465
|
-
const typeMap = {
|
|
1466
|
-
[schema_types_1.ColumnType.STRING]: 'VARCHAR',
|
|
1467
|
-
[schema_types_1.ColumnType.TEXT]: 'TEXT',
|
|
1468
|
-
[schema_types_1.ColumnType.VARCHAR]: 'VARCHAR',
|
|
1469
|
-
[schema_types_1.ColumnType.CHAR]: 'CHAR',
|
|
1470
|
-
[schema_types_1.ColumnType.INTEGER]: 'INTEGER',
|
|
1471
|
-
[schema_types_1.ColumnType.BIGINT]: 'BIGINT',
|
|
1472
|
-
[schema_types_1.ColumnType.SMALLINT]: 'SMALLINT',
|
|
1473
|
-
[schema_types_1.ColumnType.DECIMAL]: 'DECIMAL',
|
|
1474
|
-
[schema_types_1.ColumnType.NUMERIC]: 'NUMERIC',
|
|
1475
|
-
[schema_types_1.ColumnType.FLOAT]: 'REAL',
|
|
1476
|
-
[schema_types_1.ColumnType.DOUBLE]: 'DOUBLE PRECISION',
|
|
1477
|
-
[schema_types_1.ColumnType.REAL]: 'REAL',
|
|
1478
|
-
[schema_types_1.ColumnType.BOOLEAN]: 'BOOLEAN',
|
|
1479
|
-
[schema_types_1.ColumnType.DATE]: 'DATE',
|
|
1480
|
-
[schema_types_1.ColumnType.TIME]: 'TIME',
|
|
1481
|
-
[schema_types_1.ColumnType.DATETIME]: 'TIMESTAMP',
|
|
1482
|
-
[schema_types_1.ColumnType.TIMESTAMP]: 'TIMESTAMP',
|
|
1483
|
-
[schema_types_1.ColumnType.JSON]: 'JSONB',
|
|
1484
|
-
[schema_types_1.ColumnType.JSONB]: 'JSONB',
|
|
1485
|
-
[schema_types_1.ColumnType.UUID]: 'UUID',
|
|
1486
|
-
[schema_types_1.ColumnType.BLOB]: 'BYTEA',
|
|
1487
|
-
[schema_types_1.ColumnType.BINARY]: 'BYTEA',
|
|
1488
|
-
[schema_types_1.ColumnType.ARRAY]: 'ARRAY',
|
|
1489
|
-
[schema_types_1.ColumnType.OBJECT]: 'JSONB',
|
|
1490
|
-
[schema_types_1.ColumnType.ENUM]: 'VARCHAR',
|
|
1491
|
-
};
|
|
1492
|
-
return typeMap[type] || 'TEXT';
|
|
1493
|
-
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Map PostgreSQL type to ColumnType
|
|
1496
|
-
*/
|
|
1497
|
-
mapPostgreSQLTypeToColumnType(pgType) {
|
|
1498
|
-
const typeMap = {
|
|
1499
|
-
'character varying': schema_types_1.ColumnType.VARCHAR,
|
|
1500
|
-
varchar: schema_types_1.ColumnType.VARCHAR,
|
|
1501
|
-
text: schema_types_1.ColumnType.TEXT,
|
|
1502
|
-
character: schema_types_1.ColumnType.CHAR,
|
|
1503
|
-
char: schema_types_1.ColumnType.CHAR,
|
|
1504
|
-
integer: schema_types_1.ColumnType.INTEGER,
|
|
1505
|
-
bigint: schema_types_1.ColumnType.BIGINT,
|
|
1506
|
-
smallint: schema_types_1.ColumnType.SMALLINT,
|
|
1507
|
-
decimal: schema_types_1.ColumnType.DECIMAL,
|
|
1508
|
-
numeric: schema_types_1.ColumnType.NUMERIC,
|
|
1509
|
-
real: schema_types_1.ColumnType.FLOAT,
|
|
1510
|
-
'double precision': schema_types_1.ColumnType.DOUBLE,
|
|
1511
|
-
boolean: schema_types_1.ColumnType.BOOLEAN,
|
|
1512
|
-
date: schema_types_1.ColumnType.DATE,
|
|
1513
|
-
time: schema_types_1.ColumnType.TIME,
|
|
1514
|
-
timestamp: schema_types_1.ColumnType.TIMESTAMP,
|
|
1515
|
-
'timestamp without time zone': schema_types_1.ColumnType.TIMESTAMP,
|
|
1516
|
-
jsonb: schema_types_1.ColumnType.JSONB,
|
|
1517
|
-
json: schema_types_1.ColumnType.JSON,
|
|
1518
|
-
uuid: schema_types_1.ColumnType.UUID,
|
|
1519
|
-
bytea: schema_types_1.ColumnType.BINARY,
|
|
1520
|
-
};
|
|
1521
|
-
return typeMap[pgType.toLowerCase()] || schema_types_1.ColumnType.TEXT;
|
|
1522
|
-
}
|
|
1523
|
-
/**
|
|
1524
|
-
* Ensure migration table exists
|
|
1525
|
-
*/
|
|
1526
|
-
async ensureMigrationTable(client) {
|
|
1527
|
-
const query = `
|
|
1528
|
-
CREATE TABLE IF NOT EXISTS _ductape_migrations (
|
|
1529
|
-
tag VARCHAR(255) PRIMARY KEY,
|
|
1530
|
-
name VARCHAR(255) NOT NULL,
|
|
1531
|
-
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
1532
|
-
)
|
|
1533
|
-
`;
|
|
1534
|
-
await client.query(query);
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
|
-
* Record migration execution
|
|
1538
|
-
*/
|
|
1539
|
-
async recordMigration(client, migration, direction) {
|
|
1540
|
-
await this.ensureMigrationTable(client);
|
|
1541
|
-
const query = `
|
|
1542
|
-
INSERT INTO _ductape_migrations (tag, name, executed_at)
|
|
1543
|
-
VALUES ($1, $2, CURRENT_TIMESTAMP)
|
|
1544
|
-
ON CONFLICT (tag) DO UPDATE SET executed_at = CURRENT_TIMESTAMP
|
|
1545
|
-
`;
|
|
1546
|
-
await client.query(query, [migration.tag, migration.name]);
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Remove migration from history
|
|
1550
|
-
*/
|
|
1551
|
-
async removeMigration(client, tag) {
|
|
1552
|
-
await this.ensureMigrationTable(client);
|
|
1553
|
-
const query = `DELETE FROM _ductape_migrations WHERE tag = $1`;
|
|
1554
|
-
await client.query(query, [tag]);
|
|
1555
|
-
}
|
|
1556
|
-
// ==================== Utility Methods ====================
|
|
1557
|
-
/**
|
|
1558
|
-
* Escape identifier (table/column name)
|
|
1559
|
-
*/
|
|
1560
|
-
escapeIdentifier(identifier) {
|
|
1561
|
-
return `"${identifier.replace(/"/g, '""')}"`;
|
|
1562
|
-
}
|
|
1563
|
-
/**
|
|
1564
|
-
* Escape value for SQL
|
|
1565
|
-
*/
|
|
1566
|
-
escapeValue(value) {
|
|
1567
|
-
if (value === null || value === undefined) {
|
|
1568
|
-
return 'NULL';
|
|
1569
1258
|
}
|
|
1570
|
-
if (
|
|
1571
|
-
|
|
1259
|
+
if (column.nullable === false) {
|
|
1260
|
+
def += ' NOT NULL';
|
|
1572
1261
|
}
|
|
1573
|
-
if (
|
|
1574
|
-
|
|
1575
|
-
}
|
|
1576
|
-
if (value instanceof Date) {
|
|
1577
|
-
return `'${value.toISOString()}'`;
|
|
1262
|
+
if (column.unique) {
|
|
1263
|
+
def += ' UNIQUE';
|
|
1578
1264
|
}
|
|
1579
|
-
if (
|
|
1580
|
-
|
|
1265
|
+
if (column.defaultValue !== undefined) {
|
|
1266
|
+
def += ` DEFAULT ${this.escapeValue(column.defaultValue)}`;
|
|
1581
1267
|
}
|
|
1582
|
-
if (
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
async getDatabaseVersion(connection) {
|
|
1591
|
-
var _a;
|
|
1592
|
-
try {
|
|
1593
|
-
const pool = connection.getClient();
|
|
1594
|
-
const result = await pool.query('SELECT version()');
|
|
1595
|
-
return ((_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.version) || 'Unknown';
|
|
1268
|
+
if (column.references) {
|
|
1269
|
+
def += ` REFERENCES ${this.escapeIdentifier(column.references.table)}(${this.escapeIdentifier(column.references.column)})`;
|
|
1270
|
+
if (column.references.onDelete) {
|
|
1271
|
+
def += ` ON DELETE ${column.references.onDelete}`;
|
|
1272
|
+
}
|
|
1273
|
+
if (column.references.onUpdate) {
|
|
1274
|
+
def += ` ON UPDATE ${column.references.onUpdate}`;
|
|
1275
|
+
}
|
|
1596
1276
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1277
|
+
// Handle ENUM type with CHECK constraint
|
|
1278
|
+
if (column.type === enums_1.ColumnType.ENUM && column.enumValues && column.enumValues.length > 0) {
|
|
1279
|
+
const escapedValues = column.enumValues.map((v) => `'${v.replace(/'/g, "''")}'`).join(', ');
|
|
1280
|
+
def += ` CHECK (${this.escapeIdentifier(column.name)} IN (${escapedValues}))`;
|
|
1281
|
+
}
|
|
1282
|
+
// Handle custom check constraint (but don't duplicate if we just added one for ENUM)
|
|
1283
|
+
if (column.check && column.type !== enums_1.ColumnType.ENUM) {
|
|
1284
|
+
def += ` CHECK (${column.check})`;
|
|
1285
|
+
}
|
|
1286
|
+
else if (column.check && column.type === enums_1.ColumnType.ENUM) {
|
|
1287
|
+
// If ENUM has custom check, combine them
|
|
1288
|
+
def = def.replace(/\)$/, ` AND ${column.check})`);
|
|
1289
|
+
}
|
|
1290
|
+
return def;
|
|
1291
|
+
}
|
|
1292
|
+
buildConstraintDefinition(constraint) {
|
|
1293
|
+
let def = `CONSTRAINT ${this.escapeIdentifier(constraint.name)}`;
|
|
1294
|
+
switch (constraint.type) {
|
|
1295
|
+
case 'PRIMARY_KEY':
|
|
1296
|
+
def += ` PRIMARY KEY (${constraint.columns.map((c) => this.escapeIdentifier(c)).join(', ')})`;
|
|
1297
|
+
break;
|
|
1298
|
+
case 'UNIQUE':
|
|
1299
|
+
def += ` UNIQUE (${constraint.columns.map((c) => this.escapeIdentifier(c)).join(', ')})`;
|
|
1300
|
+
break;
|
|
1301
|
+
case 'FOREIGN_KEY':
|
|
1302
|
+
def += ` FOREIGN KEY (${constraint.columns.map((c) => this.escapeIdentifier(c)).join(', ')})`;
|
|
1303
|
+
def += ` REFERENCES ${this.escapeIdentifier(constraint.references.table)}(${this.escapeIdentifier(constraint.references.column)})`;
|
|
1304
|
+
if (constraint.references.onDelete) {
|
|
1305
|
+
def += ` ON DELETE ${constraint.references.onDelete}`;
|
|
1306
|
+
}
|
|
1307
|
+
if (constraint.references.onUpdate) {
|
|
1308
|
+
def += ` ON UPDATE ${constraint.references.onUpdate}`;
|
|
1309
|
+
}
|
|
1310
|
+
break;
|
|
1311
|
+
case 'CHECK':
|
|
1312
|
+
def += ` CHECK (${constraint.expression})`;
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
return def;
|
|
1316
|
+
}
|
|
1317
|
+
mapIsolationLevel(level) {
|
|
1318
|
+
switch (level) {
|
|
1319
|
+
case enums_1.IsolationLevel.READ_UNCOMMITTED:
|
|
1320
|
+
return 'READ UNCOMMITTED';
|
|
1321
|
+
case enums_1.IsolationLevel.READ_COMMITTED:
|
|
1322
|
+
return 'READ COMMITTED';
|
|
1323
|
+
case enums_1.IsolationLevel.REPEATABLE_READ:
|
|
1324
|
+
return 'REPEATABLE READ';
|
|
1325
|
+
case enums_1.IsolationLevel.SERIALIZABLE:
|
|
1326
|
+
return 'SERIALIZABLE';
|
|
1327
|
+
default:
|
|
1328
|
+
return 'READ COMMITTED';
|
|
1599
1329
|
}
|
|
1600
1330
|
}
|
|
1601
1331
|
}
|