@ductape/sdk 0.0.4-v51 → 0.0.4-v53
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
|
-
* MySQL
|
|
4
|
-
*
|
|
3
|
+
* MySQL Adapter
|
|
4
|
+
*
|
|
5
|
+
* Database adapter for MySQL databases using the 'mysql2' library.
|
|
6
|
+
* Implements all methods from BaseAdapter with MySQL-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,1425 +41,881 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
42
|
exports.MySQLAdapter = 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");
|
|
44
|
+
const enums_1 = require("../types/enums");
|
|
45
|
+
const database_error_1 = require("../utils/database-error");
|
|
46
46
|
/**
|
|
47
|
-
* MySQL
|
|
47
|
+
* MySQL database adapter
|
|
48
|
+
* Provides MySQL-specific implementations for all database operations
|
|
48
49
|
*/
|
|
49
|
-
class
|
|
50
|
-
constructor(id, connection) {
|
|
51
|
-
this.id = id;
|
|
52
|
-
this.type = database_types_1.DatabaseType.MYSQL;
|
|
53
|
-
this.status = database_types_1.ConnectionStatus.CONNECTED;
|
|
54
|
-
this.connection = connection;
|
|
55
|
-
}
|
|
56
|
-
async connect() {
|
|
57
|
-
this.status = database_types_1.ConnectionStatus.CONNECTED;
|
|
58
|
-
}
|
|
59
|
-
async disconnect() {
|
|
60
|
-
if (this.connection) {
|
|
61
|
-
await this.connection.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.connection;
|
|
70
|
-
}
|
|
71
|
-
getType() {
|
|
72
|
-
return this.type;
|
|
73
|
-
}
|
|
74
|
-
getConfig() {
|
|
75
|
-
throw new Error('Config not stored in connection');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* MySQL Savepoint implementation
|
|
80
|
-
*/
|
|
81
|
-
class MySQLSavepoint {
|
|
82
|
-
constructor(name, transaction, client) {
|
|
83
|
-
this.name = name;
|
|
84
|
-
this.transaction = transaction;
|
|
85
|
-
this.createdAt = new Date();
|
|
86
|
-
this.client = client;
|
|
87
|
-
}
|
|
88
|
-
async rollback() {
|
|
89
|
-
await this.client.query(`ROLLBACK TO SAVEPOINT \`${this.name}\``);
|
|
90
|
-
}
|
|
91
|
-
async release() {
|
|
92
|
-
await this.client.query(`RELEASE SAVEPOINT \`${this.name}\``);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* MySQL Transaction implementation
|
|
97
|
-
*/
|
|
98
|
-
class MySQLTransaction {
|
|
99
|
-
constructor(connection, client, options) {
|
|
100
|
-
this.id = (0, uuid_1.v4)();
|
|
101
|
-
this.connection = connection;
|
|
102
|
-
this.status = database_types_1.TransactionStatus.ACTIVE;
|
|
103
|
-
this.isolationLevel = options === null || options === void 0 ? void 0 : options.isolationLevel;
|
|
104
|
-
this.createdAt = new Date();
|
|
105
|
-
this.client = client;
|
|
106
|
-
this.native = client;
|
|
107
|
-
}
|
|
108
|
-
async commit() {
|
|
109
|
-
if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
|
|
110
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot commit transaction: status is ${this.status}`);
|
|
111
|
-
}
|
|
112
|
-
await this.client.commit();
|
|
113
|
-
this.status = database_types_1.TransactionStatus.COMMITTED;
|
|
114
|
-
}
|
|
115
|
-
async rollback() {
|
|
116
|
-
if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
|
|
117
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot rollback transaction: status is ${this.status}`);
|
|
118
|
-
}
|
|
119
|
-
await this.client.rollback();
|
|
120
|
-
this.status = database_types_1.TransactionStatus.ROLLED_BACK;
|
|
121
|
-
}
|
|
122
|
-
async savepoint(name) {
|
|
123
|
-
if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
|
|
124
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot create savepoint: transaction status is ${this.status}`);
|
|
125
|
-
}
|
|
126
|
-
await this.client.query(`SAVEPOINT \`${name}\``);
|
|
127
|
-
return new MySQLSavepoint(name, this, this.client);
|
|
128
|
-
}
|
|
129
|
-
isActive() {
|
|
130
|
-
return this.status === database_types_1.TransactionStatus.ACTIVE;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* MySQL Database Adapter
|
|
135
|
-
*/
|
|
136
|
-
class MySQLAdapter extends base_adapter_1.BaseDatabaseAdapter {
|
|
50
|
+
class MySQLAdapter extends base_adapter_1.BaseAdapter {
|
|
137
51
|
constructor() {
|
|
138
52
|
super(...arguments);
|
|
139
|
-
this.
|
|
53
|
+
this.databaseType = enums_1.DatabaseType.MYSQL;
|
|
54
|
+
this.pool = null;
|
|
140
55
|
}
|
|
141
|
-
// ====================
|
|
142
|
-
async connect(
|
|
143
|
-
var _a, _b, _c, _d, _e, _f;
|
|
56
|
+
// ==================== CONNECTION METHODS ====================
|
|
57
|
+
async connect(options) {
|
|
144
58
|
try {
|
|
145
|
-
// Dynamic import of mysql2
|
|
146
|
-
// @ts-ignore - mysql2 is an optional peer dependency
|
|
59
|
+
// Dynamic import of mysql2 to avoid bundling issues
|
|
147
60
|
const mysql = await Promise.resolve().then(() => __importStar(require('mysql2/promise')));
|
|
148
|
-
|
|
149
|
-
|
|
61
|
+
this.connectionUrl = options.connectionUrl;
|
|
62
|
+
// Parse connection URL to extract components
|
|
63
|
+
const url = new URL(options.connectionUrl);
|
|
64
|
+
this.pool = mysql.createPool({
|
|
65
|
+
host: url.hostname,
|
|
66
|
+
port: parseInt(url.port) || 3306,
|
|
67
|
+
user: url.username,
|
|
68
|
+
password: url.password,
|
|
69
|
+
database: url.pathname.slice(1),
|
|
70
|
+
waitForConnections: true,
|
|
71
|
+
connectionLimit: options.poolSize || 10,
|
|
72
|
+
queueLimit: 0,
|
|
73
|
+
connectTimeout: options.connectionTimeout || 10000,
|
|
74
|
+
ssl: options.ssl ? { rejectUnauthorized: false } : undefined,
|
|
75
|
+
});
|
|
76
|
+
// Test the connection
|
|
77
|
+
const connection = await this.pool.getConnection();
|
|
78
|
+
const [rows] = await connection.query('SELECT VERSION() as version');
|
|
79
|
+
connection.release();
|
|
80
|
+
this.client = this.pool;
|
|
81
|
+
this.connected = true;
|
|
82
|
+
return {
|
|
83
|
+
connected: true,
|
|
84
|
+
version: rows[0].version,
|
|
85
|
+
};
|
|
150
86
|
}
|
|
151
87
|
catch (error) {
|
|
152
|
-
throw
|
|
88
|
+
throw database_error_1.DatabaseError.connectionError(`Failed to connect to MySQL: ${error.message}`, error);
|
|
153
89
|
}
|
|
154
90
|
}
|
|
155
|
-
async
|
|
156
|
-
await connection.disconnect();
|
|
157
|
-
}
|
|
158
|
-
async testConnection(connection) {
|
|
159
|
-
const startTime = Date.now();
|
|
91
|
+
async testConnection(options) {
|
|
160
92
|
try {
|
|
161
|
-
const
|
|
162
|
-
|
|
93
|
+
const mysql = await Promise.resolve().then(() => __importStar(require('mysql2/promise')));
|
|
94
|
+
const url = new URL(options.connectionUrl);
|
|
95
|
+
const connection = await mysql.createConnection({
|
|
96
|
+
host: url.hostname,
|
|
97
|
+
port: parseInt(url.port) || 3306,
|
|
98
|
+
user: url.username,
|
|
99
|
+
password: url.password,
|
|
100
|
+
database: url.pathname.slice(1),
|
|
101
|
+
connectTimeout: options.connectionTimeout || 5000,
|
|
102
|
+
});
|
|
103
|
+
const [rows] = await connection.query('SELECT VERSION() as version');
|
|
104
|
+
await connection.end();
|
|
163
105
|
return {
|
|
164
106
|
connected: true,
|
|
165
|
-
|
|
166
|
-
databaseType: 'MySQL',
|
|
167
|
-
responseTime: Date.now() - startTime,
|
|
107
|
+
version: rows[0].version,
|
|
168
108
|
};
|
|
169
109
|
}
|
|
170
110
|
catch (error) {
|
|
171
111
|
return {
|
|
172
112
|
connected: false,
|
|
173
|
-
message: `MySQL connection failed: ${error.message}`,
|
|
174
|
-
databaseType: 'MySQL',
|
|
175
|
-
responseTime: Date.now() - startTime,
|
|
176
|
-
error: error.message,
|
|
177
113
|
};
|
|
178
114
|
}
|
|
179
115
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const isolationLevel = options.isolationLevel.replace('_', ' ');
|
|
187
|
-
await conn.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`);
|
|
188
|
-
}
|
|
189
|
-
// Set read-only mode if specified
|
|
190
|
-
if (options === null || options === void 0 ? void 0 : options.readOnly) {
|
|
191
|
-
await conn.query('SET TRANSACTION READ ONLY');
|
|
192
|
-
}
|
|
193
|
-
await conn.beginTransaction();
|
|
194
|
-
return new MySQLTransaction(connection, conn, options);
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Failed to begin transaction: ${error.message}`, error);
|
|
116
|
+
async disconnect() {
|
|
117
|
+
if (this.pool) {
|
|
118
|
+
await this.pool.end();
|
|
119
|
+
this.pool = null;
|
|
120
|
+
this.client = null;
|
|
121
|
+
this.connected = false;
|
|
198
122
|
}
|
|
199
123
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
await transaction.rollback();
|
|
205
|
-
}
|
|
206
|
-
async createSavepoint(connection, transaction, savepointName) {
|
|
207
|
-
return transaction.savepoint(savepointName);
|
|
208
|
-
}
|
|
209
|
-
async rollbackToSavepoint(_connection, _transaction, savepoint) {
|
|
210
|
-
await savepoint.rollback();
|
|
211
|
-
}
|
|
212
|
-
async releaseSavepoint(_connection, _transaction, savepoint) {
|
|
213
|
-
await savepoint.release();
|
|
214
|
-
}
|
|
215
|
-
// ==================== Query Methods ====================
|
|
216
|
-
async query(connection, options) {
|
|
217
|
-
const startTime = Date.now();
|
|
124
|
+
// ==================== QUERY METHODS ====================
|
|
125
|
+
async query(query) {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
this.ensureConnected();
|
|
218
128
|
try {
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
129
|
+
const connection = ((_a = query.options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
130
|
+
const [rows, fields] = await connection.query(query.sql, query.params);
|
|
131
|
+
// Get total count if needed for pagination
|
|
132
|
+
let count = rows.length;
|
|
133
|
+
if (query.options.limit || query.options.offset) {
|
|
134
|
+
const countSql = this.buildCountQuery(query);
|
|
135
|
+
// Calculate how many params to remove based on actual pagination options
|
|
136
|
+
let paramsToRemove = 0;
|
|
137
|
+
if (query.options.limit !== undefined)
|
|
138
|
+
paramsToRemove++;
|
|
139
|
+
if (query.options.offset !== undefined)
|
|
140
|
+
paramsToRemove++;
|
|
141
|
+
const countParams = paramsToRemove > 0 ? (_b = query.params) === null || _b === void 0 ? void 0 : _b.slice(0, -paramsToRemove) : query.params;
|
|
142
|
+
const [countRows] = await connection.query(countSql, countParams);
|
|
143
|
+
count = countRows[0].count;
|
|
144
|
+
}
|
|
223
145
|
return {
|
|
224
146
|
data: rows,
|
|
225
|
-
count
|
|
226
|
-
|
|
147
|
+
count,
|
|
148
|
+
fields: fields === null || fields === void 0 ? void 0 : fields.map((f) => f.name),
|
|
227
149
|
};
|
|
228
150
|
}
|
|
229
151
|
catch (error) {
|
|
230
|
-
throw
|
|
152
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
231
153
|
}
|
|
232
154
|
}
|
|
233
|
-
async
|
|
234
|
-
|
|
155
|
+
async raw(options) {
|
|
156
|
+
var _a;
|
|
157
|
+
this.ensureConnected();
|
|
235
158
|
try {
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
const executionTime = Date.now() - startTime;
|
|
159
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
160
|
+
const [rows, fields] = await connection.query(options.query, options.params);
|
|
161
|
+
const isArray = Array.isArray(rows);
|
|
240
162
|
return {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
executionTime,
|
|
245
|
-
success: true,
|
|
163
|
+
data: (isArray ? rows : []),
|
|
164
|
+
count: isArray ? rows.length : 0,
|
|
165
|
+
fields: fields === null || fields === void 0 ? void 0 : fields.map((f) => f.name),
|
|
246
166
|
};
|
|
247
167
|
}
|
|
248
168
|
catch (error) {
|
|
249
|
-
throw
|
|
169
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
250
170
|
}
|
|
251
171
|
}
|
|
252
|
-
|
|
253
|
-
|
|
172
|
+
// ==================== WRITE METHODS ====================
|
|
173
|
+
async insert(options) {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
this.ensureConnected();
|
|
254
176
|
try {
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
177
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
178
|
+
const data = Array.isArray(options.data) ? options.data : [options.data];
|
|
179
|
+
if (data.length === 0) {
|
|
180
|
+
return { data: [], count: 0, insertedIds: [] };
|
|
181
|
+
}
|
|
182
|
+
const columns = Object.keys(data[0]);
|
|
183
|
+
const values = [];
|
|
184
|
+
const valuePlaceholders = [];
|
|
185
|
+
data.forEach((record) => {
|
|
186
|
+
const rowPlaceholders = [];
|
|
187
|
+
columns.forEach((col) => {
|
|
188
|
+
values.push(record[col]);
|
|
189
|
+
rowPlaceholders.push('?');
|
|
190
|
+
});
|
|
191
|
+
valuePlaceholders.push(`(${rowPlaceholders.join(', ')})`);
|
|
192
|
+
});
|
|
193
|
+
let sql = `INSERT INTO ${this.escapeIdentifier(options.table)} (${columns.map(c => this.escapeIdentifier(c)).join(', ')}) VALUES ${valuePlaceholders.join(', ')}`;
|
|
194
|
+
// Handle ON DUPLICATE KEY (upsert)
|
|
195
|
+
if (options.onConflict) {
|
|
196
|
+
if (options.onConflict.action === 'ignore') {
|
|
197
|
+
sql = sql.replace('INSERT INTO', 'INSERT IGNORE INTO');
|
|
198
|
+
}
|
|
199
|
+
else if (options.onConflict.action === 'update' && options.onConflict.update) {
|
|
200
|
+
const updates = options.onConflict.update.map(col => `${this.escapeIdentifier(col)} = VALUES(${this.escapeIdentifier(col)})`).join(', ');
|
|
201
|
+
sql += ` ON DUPLICATE KEY UPDATE ${updates}`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const [result] = await connection.query(sql, values);
|
|
205
|
+
// Get inserted IDs
|
|
206
|
+
const insertedIds = [];
|
|
207
|
+
const insertId = result.insertId;
|
|
208
|
+
const affectedRows = result.affectedRows;
|
|
209
|
+
// MySQL's insertId only works for AUTO_INCREMENT columns
|
|
210
|
+
// If insertId is 0, it means no AUTO_INCREMENT column or value wasn't generated
|
|
211
|
+
if (insertId > 0) {
|
|
212
|
+
for (let i = 0; i < data.length; i++) {
|
|
213
|
+
insertedIds.push(insertId + i);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// If returning is requested, fetch the inserted records
|
|
217
|
+
let returnedData = [];
|
|
218
|
+
if (options.returning) {
|
|
219
|
+
// If we have insertedIds from AUTO_INCREMENT, try to find primary key column
|
|
220
|
+
if (insertedIds.length > 0) {
|
|
221
|
+
// Get the primary key column name from the table
|
|
222
|
+
const [pkResult] = await connection.query(`SELECT COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE
|
|
223
|
+
WHERE TABLE_SCHEMA = DATABASE()
|
|
224
|
+
AND TABLE_NAME = ?
|
|
225
|
+
AND CONSTRAINT_NAME = 'PRIMARY'
|
|
226
|
+
ORDER BY ORDINAL_POSITION LIMIT 1`, [options.table]);
|
|
227
|
+
const pkColumn = ((_b = pkResult[0]) === null || _b === void 0 ? void 0 : _b.COLUMN_NAME) || 'id';
|
|
228
|
+
const [rows] = await connection.query(`SELECT * FROM ${this.escapeIdentifier(options.table)} WHERE ${this.escapeIdentifier(pkColumn)} IN (?)`, [insertedIds]);
|
|
229
|
+
returnedData = rows;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// No AUTO_INCREMENT - fetch by matching the inserted data's values
|
|
233
|
+
// Build WHERE clauses to match each inserted record
|
|
234
|
+
const whereConditions = [];
|
|
235
|
+
const whereValues = [];
|
|
236
|
+
for (const record of data) {
|
|
237
|
+
const conditions = [];
|
|
238
|
+
for (const [col, val] of Object.entries(record)) {
|
|
239
|
+
if (val === null) {
|
|
240
|
+
conditions.push(`${this.escapeIdentifier(col)} IS NULL`);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
conditions.push(`${this.escapeIdentifier(col)} = ?`);
|
|
244
|
+
whereValues.push(val);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
whereConditions.push(`(${conditions.join(' AND ')})`);
|
|
248
|
+
}
|
|
249
|
+
if (whereConditions.length > 0) {
|
|
250
|
+
const [rows] = await connection.query(`SELECT * FROM ${this.escapeIdentifier(options.table)} WHERE ${whereConditions.join(' OR ')}`, whereValues);
|
|
251
|
+
returnedData = rows;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
259
255
|
return {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
executionTime,
|
|
264
|
-
success: true,
|
|
256
|
+
data: returnedData,
|
|
257
|
+
count: affectedRows,
|
|
258
|
+
insertedIds,
|
|
265
259
|
};
|
|
266
260
|
}
|
|
267
261
|
catch (error) {
|
|
268
|
-
throw
|
|
262
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
269
263
|
}
|
|
270
264
|
}
|
|
271
|
-
async
|
|
272
|
-
|
|
265
|
+
async update(options) {
|
|
266
|
+
var _a;
|
|
267
|
+
this.ensureConnected();
|
|
273
268
|
try {
|
|
274
|
-
const
|
|
275
|
-
const
|
|
276
|
-
const
|
|
277
|
-
|
|
269
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
270
|
+
const setClauses = [];
|
|
271
|
+
const values = [];
|
|
272
|
+
// Build SET clause
|
|
273
|
+
for (const [key, value] of Object.entries(options.data)) {
|
|
274
|
+
if (value && typeof value === 'object' && this.isUpdateOperator(value)) {
|
|
275
|
+
// Handle update operators
|
|
276
|
+
if ('$INC' in value) {
|
|
277
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ${this.escapeIdentifier(key)} + ?`);
|
|
278
|
+
values.push(value.$INC);
|
|
279
|
+
}
|
|
280
|
+
else if ('$DEC' in value) {
|
|
281
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ${this.escapeIdentifier(key)} - ?`);
|
|
282
|
+
values.push(value.$DEC);
|
|
283
|
+
}
|
|
284
|
+
else if ('$MUL' in value) {
|
|
285
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ${this.escapeIdentifier(key)} * ?`);
|
|
286
|
+
values.push(value.$MUL);
|
|
287
|
+
}
|
|
288
|
+
else if ('$MIN' in value) {
|
|
289
|
+
// LEAST function for minimum
|
|
290
|
+
setClauses.push(`${this.escapeIdentifier(key)} = LEAST(${this.escapeIdentifier(key)}, ?)`);
|
|
291
|
+
values.push(value.$MIN);
|
|
292
|
+
}
|
|
293
|
+
else if ('$MAX' in value) {
|
|
294
|
+
// GREATEST function for maximum
|
|
295
|
+
setClauses.push(`${this.escapeIdentifier(key)} = GREATEST(${this.escapeIdentifier(key)}, ?)`);
|
|
296
|
+
values.push(value.$MAX);
|
|
297
|
+
}
|
|
298
|
+
else if ('$SET' in value) {
|
|
299
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ?`);
|
|
300
|
+
values.push(value.$SET);
|
|
301
|
+
}
|
|
302
|
+
else if ('$UNSET' in value && value.$UNSET) {
|
|
303
|
+
setClauses.push(`${this.escapeIdentifier(key)} = NULL`);
|
|
304
|
+
}
|
|
305
|
+
else if ('$PUSH' in value) {
|
|
306
|
+
// JSON array append for MySQL (column must be JSON type)
|
|
307
|
+
setClauses.push(`${this.escapeIdentifier(key)} = JSON_ARRAY_APPEND(COALESCE(${this.escapeIdentifier(key)}, '[]'), '$', ?)`);
|
|
308
|
+
values.push(value.$PUSH);
|
|
309
|
+
}
|
|
310
|
+
else if ('$PULL' in value) {
|
|
311
|
+
// JSON array remove for MySQL - requires JSON_REMOVE with path, complex operation
|
|
312
|
+
// For simplicity, use JSON_REMOVE with search
|
|
313
|
+
setClauses.push(`${this.escapeIdentifier(key)} = JSON_REMOVE(${this.escapeIdentifier(key)}, JSON_UNQUOTE(JSON_SEARCH(${this.escapeIdentifier(key)}, 'one', ?)))`);
|
|
314
|
+
values.push(value.$PULL);
|
|
315
|
+
}
|
|
316
|
+
else if ('$ADDTOSET' in value) {
|
|
317
|
+
// Add unique to JSON array - use IF to check existence
|
|
318
|
+
setClauses.push(`${this.escapeIdentifier(key)} = IF(JSON_CONTAINS(COALESCE(${this.escapeIdentifier(key)}, '[]'), JSON_QUOTE(?)), ${this.escapeIdentifier(key)}, JSON_ARRAY_APPEND(COALESCE(${this.escapeIdentifier(key)}, '[]'), '$', ?))`);
|
|
319
|
+
values.push(value.$ADDTOSET, value.$ADDTOSET);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
setClauses.push(`${this.escapeIdentifier(key)} = ?`);
|
|
324
|
+
values.push(value);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
let sql = `UPDATE ${this.escapeIdentifier(options.table)} SET ${setClauses.join(', ')}`;
|
|
328
|
+
// Build WHERE clause
|
|
329
|
+
if (options.where) {
|
|
330
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
331
|
+
sql += ` WHERE ${whereClause}`;
|
|
332
|
+
values.push(...whereParams);
|
|
333
|
+
}
|
|
334
|
+
const [result] = await connection.query(sql, values);
|
|
335
|
+
const affectedRows = result.affectedRows;
|
|
336
|
+
// If returning is requested, fetch updated records
|
|
337
|
+
let returnedData = [];
|
|
338
|
+
if (options.returning && options.where) {
|
|
339
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
340
|
+
const [rows] = await connection.query(`SELECT * FROM ${this.escapeIdentifier(options.table)} WHERE ${whereClause}`, whereParams);
|
|
341
|
+
returnedData = rows;
|
|
342
|
+
}
|
|
278
343
|
return {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
executionTime,
|
|
282
|
-
success: true,
|
|
344
|
+
data: returnedData,
|
|
345
|
+
count: affectedRows,
|
|
283
346
|
};
|
|
284
347
|
}
|
|
285
348
|
catch (error) {
|
|
286
|
-
throw
|
|
349
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
287
350
|
}
|
|
288
351
|
}
|
|
289
|
-
async
|
|
290
|
-
|
|
352
|
+
async delete(options) {
|
|
353
|
+
var _a;
|
|
354
|
+
this.ensureConnected();
|
|
291
355
|
try {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
356
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
357
|
+
let sql = `DELETE FROM ${this.escapeIdentifier(options.table)}`;
|
|
358
|
+
const values = [];
|
|
359
|
+
// Fetch records before delete if returning is requested
|
|
360
|
+
let deletedData;
|
|
361
|
+
if (options.returning && options.where) {
|
|
362
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
363
|
+
const [rows] = await connection.query(`SELECT * FROM ${this.escapeIdentifier(options.table)} WHERE ${whereClause}`, whereParams);
|
|
364
|
+
deletedData = rows;
|
|
365
|
+
}
|
|
366
|
+
// Build WHERE clause
|
|
367
|
+
if (options.where) {
|
|
368
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
369
|
+
sql += ` WHERE ${whereClause}`;
|
|
370
|
+
values.push(...whereParams);
|
|
371
|
+
}
|
|
372
|
+
const [result] = await connection.query(sql, values);
|
|
296
373
|
return {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
affectedCount: result.affectedRows,
|
|
300
|
-
data: undefined,
|
|
301
|
-
executionTime,
|
|
302
|
-
success: true,
|
|
374
|
+
count: result.affectedRows,
|
|
375
|
+
data: deletedData,
|
|
303
376
|
};
|
|
304
377
|
}
|
|
305
378
|
catch (error) {
|
|
306
|
-
throw
|
|
379
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
307
380
|
}
|
|
308
381
|
}
|
|
309
|
-
async
|
|
310
|
-
|
|
382
|
+
async upsert(options) {
|
|
383
|
+
this.ensureConnected();
|
|
311
384
|
try {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
385
|
+
const insertResult = await this.insert(Object.assign(Object.assign({}, options), { onConflict: {
|
|
386
|
+
columns: options.conflictKeys,
|
|
387
|
+
action: 'update',
|
|
388
|
+
update: options.updateColumns || Object.keys(options.data).filter(k => !options.conflictKeys.includes(k)),
|
|
389
|
+
}, returning: true }));
|
|
315
390
|
return {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
name: f.name,
|
|
320
|
-
type: f.type,
|
|
321
|
-
})),
|
|
322
|
-
executionTime,
|
|
391
|
+
data: insertResult.data,
|
|
392
|
+
count: insertResult.count,
|
|
393
|
+
operation: insertResult.count > 0 ? 'inserted' : 'updated',
|
|
323
394
|
};
|
|
324
395
|
}
|
|
325
396
|
catch (error) {
|
|
326
|
-
throw
|
|
397
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
327
398
|
}
|
|
328
399
|
}
|
|
329
|
-
// ====================
|
|
330
|
-
async count(
|
|
400
|
+
// ==================== AGGREGATION METHODS ====================
|
|
401
|
+
async count(options) {
|
|
402
|
+
var _a;
|
|
403
|
+
this.ensureConnected();
|
|
331
404
|
try {
|
|
332
|
-
const
|
|
333
|
-
const
|
|
334
|
-
const
|
|
335
|
-
|
|
405
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
406
|
+
const column = options.column ? this.escapeIdentifier(options.column) : '*';
|
|
407
|
+
const distinctPrefix = options.distinct ? 'DISTINCT ' : '';
|
|
408
|
+
let sql = `SELECT COUNT(${distinctPrefix}${column}) as count FROM ${this.escapeIdentifier(options.table)}`;
|
|
409
|
+
const values = [];
|
|
410
|
+
if (options.where) {
|
|
411
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
412
|
+
sql += ` WHERE ${whereClause}`;
|
|
413
|
+
values.push(...whereParams);
|
|
414
|
+
}
|
|
415
|
+
const [rows] = await connection.query(sql, values);
|
|
416
|
+
return rows[0].count;
|
|
336
417
|
}
|
|
337
418
|
catch (error) {
|
|
338
|
-
throw
|
|
419
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
339
420
|
}
|
|
340
421
|
}
|
|
341
|
-
async sum(
|
|
422
|
+
async sum(options) {
|
|
423
|
+
var _a;
|
|
424
|
+
this.ensureConnected();
|
|
342
425
|
try {
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
426
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
427
|
+
let sql = `SELECT COALESCE(SUM(${this.escapeIdentifier(options.column)}), 0) as sum FROM ${this.escapeIdentifier(options.table)}`;
|
|
428
|
+
const values = [];
|
|
429
|
+
if (options.where) {
|
|
430
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
431
|
+
sql += ` WHERE ${whereClause}`;
|
|
432
|
+
values.push(...whereParams);
|
|
433
|
+
}
|
|
434
|
+
const [rows] = await connection.query(sql, values);
|
|
435
|
+
return parseFloat(rows[0].sum);
|
|
347
436
|
}
|
|
348
437
|
catch (error) {
|
|
349
|
-
throw
|
|
438
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
350
439
|
}
|
|
351
440
|
}
|
|
352
|
-
async avg(
|
|
441
|
+
async avg(options) {
|
|
442
|
+
var _a;
|
|
443
|
+
this.ensureConnected();
|
|
353
444
|
try {
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
445
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
446
|
+
let sql = `SELECT COALESCE(AVG(${this.escapeIdentifier(options.column)}), 0) as avg FROM ${this.escapeIdentifier(options.table)}`;
|
|
447
|
+
const values = [];
|
|
448
|
+
if (options.where) {
|
|
449
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
450
|
+
sql += ` WHERE ${whereClause}`;
|
|
451
|
+
values.push(...whereParams);
|
|
452
|
+
}
|
|
453
|
+
const [rows] = await connection.query(sql, values);
|
|
454
|
+
return parseFloat(rows[0].avg);
|
|
358
455
|
}
|
|
359
456
|
catch (error) {
|
|
360
|
-
throw
|
|
457
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
361
458
|
}
|
|
362
459
|
}
|
|
363
|
-
async min(
|
|
460
|
+
async min(options) {
|
|
461
|
+
var _a;
|
|
462
|
+
this.ensureConnected();
|
|
364
463
|
try {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
|
|
464
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
465
|
+
let sql = `SELECT MIN(${this.escapeIdentifier(options.column)}) as min FROM ${this.escapeIdentifier(options.table)}`;
|
|
466
|
+
const values = [];
|
|
467
|
+
if (options.where) {
|
|
468
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
469
|
+
sql += ` WHERE ${whereClause}`;
|
|
470
|
+
values.push(...whereParams);
|
|
471
|
+
}
|
|
472
|
+
const [rows] = await connection.query(sql, values);
|
|
473
|
+
return rows[0].min;
|
|
369
474
|
}
|
|
370
475
|
catch (error) {
|
|
371
|
-
throw
|
|
476
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
372
477
|
}
|
|
373
478
|
}
|
|
374
|
-
async max(
|
|
479
|
+
async max(options) {
|
|
480
|
+
var _a;
|
|
481
|
+
this.ensureConnected();
|
|
375
482
|
try {
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
const
|
|
379
|
-
|
|
483
|
+
const connection = ((_a = options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
484
|
+
let sql = `SELECT MAX(${this.escapeIdentifier(options.column)}) as max FROM ${this.escapeIdentifier(options.table)}`;
|
|
485
|
+
const values = [];
|
|
486
|
+
if (options.where) {
|
|
487
|
+
const { whereClause, whereParams } = this.buildWhereClause(options.where);
|
|
488
|
+
sql += ` WHERE ${whereClause}`;
|
|
489
|
+
values.push(...whereParams);
|
|
490
|
+
}
|
|
491
|
+
const [rows] = await connection.query(sql, values);
|
|
492
|
+
return rows[0].max;
|
|
380
493
|
}
|
|
381
494
|
catch (error) {
|
|
382
|
-
throw
|
|
495
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
383
496
|
}
|
|
384
497
|
}
|
|
385
|
-
async
|
|
498
|
+
async aggregate(builtAggregation) {
|
|
499
|
+
var _a;
|
|
500
|
+
this.ensureConnected();
|
|
386
501
|
try {
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
return rows;
|
|
502
|
+
const connection = ((_a = builtAggregation.options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
503
|
+
const [rows] = await connection.query(builtAggregation.sql, builtAggregation.params);
|
|
504
|
+
return rows[0] || {};
|
|
391
505
|
}
|
|
392
506
|
catch (error) {
|
|
393
|
-
throw
|
|
507
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
394
508
|
}
|
|
395
509
|
}
|
|
396
|
-
async
|
|
510
|
+
async groupBy(builtGroupBy) {
|
|
511
|
+
var _a;
|
|
512
|
+
this.ensureConnected();
|
|
397
513
|
try {
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
514
|
+
const connection = ((_a = builtGroupBy.options.transaction) === null || _a === void 0 ? void 0 : _a.client) || this.pool;
|
|
515
|
+
const [rows] = await connection.query(builtGroupBy.sql, builtGroupBy.params);
|
|
516
|
+
// Transform rows into IGroupByResult format
|
|
517
|
+
const options = builtGroupBy.options;
|
|
518
|
+
return rows.map((row) => {
|
|
519
|
+
var _a;
|
|
520
|
+
const group = {};
|
|
521
|
+
const aggregates = {};
|
|
522
|
+
for (const key of Object.keys(row)) {
|
|
523
|
+
if ((_a = options.groupBy) === null || _a === void 0 ? void 0 : _a.includes(key)) {
|
|
524
|
+
group[key] = row[key];
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
aggregates[key] = row[key];
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return { group, aggregates: aggregates };
|
|
531
|
+
});
|
|
402
532
|
}
|
|
403
533
|
catch (error) {
|
|
404
|
-
throw
|
|
534
|
+
throw database_error_1.DatabaseError.fromDatabaseError(error, 'mysql');
|
|
405
535
|
}
|
|
406
536
|
}
|
|
407
|
-
// ====================
|
|
408
|
-
async
|
|
409
|
-
|
|
537
|
+
// ==================== TRANSACTION METHODS ====================
|
|
538
|
+
async beginTransaction(isolationLevel, readOnly, timeout) {
|
|
539
|
+
this.ensureConnected();
|
|
410
540
|
try {
|
|
411
|
-
const
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
541
|
+
const connection = await this.pool.getConnection();
|
|
542
|
+
const id = `mysql_txn_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
543
|
+
// Set isolation level if specified
|
|
544
|
+
if (isolationLevel) {
|
|
545
|
+
await connection.query(`SET TRANSACTION ISOLATION LEVEL ${this.mapIsolationLevel(isolationLevel)}`);
|
|
546
|
+
}
|
|
547
|
+
// Set read-only if specified
|
|
548
|
+
if (readOnly) {
|
|
549
|
+
await connection.query('SET TRANSACTION READ ONLY');
|
|
550
|
+
}
|
|
551
|
+
// Begin transaction
|
|
552
|
+
await connection.query('START TRANSACTION');
|
|
553
|
+
// Set timeout if specified
|
|
554
|
+
if (timeout) {
|
|
555
|
+
await connection.query(`SET SESSION MAX_EXECUTION_TIME = ${timeout}`);
|
|
556
|
+
}
|
|
415
557
|
return {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
558
|
+
id,
|
|
559
|
+
databaseType: 'mysql',
|
|
560
|
+
isolationLevel: isolationLevel || enums_1.IsolationLevel.READ_COMMITTED,
|
|
561
|
+
readOnly: readOnly || false,
|
|
562
|
+
timeout,
|
|
563
|
+
startedAt: new Date(),
|
|
564
|
+
client: connection,
|
|
565
|
+
savepoints: new Map(),
|
|
566
|
+
status: 'active',
|
|
420
567
|
};
|
|
421
568
|
}
|
|
422
569
|
catch (error) {
|
|
423
|
-
|
|
424
|
-
success: false,
|
|
425
|
-
operation: 'create',
|
|
426
|
-
table: schema.name,
|
|
427
|
-
error: error.message,
|
|
428
|
-
executionTime: Date.now() - startTime,
|
|
429
|
-
};
|
|
570
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to begin transaction: ${error.message}`, error);
|
|
430
571
|
}
|
|
431
572
|
}
|
|
432
|
-
async
|
|
433
|
-
const startTime = Date.now();
|
|
573
|
+
async commitTransaction(context) {
|
|
434
574
|
try {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
success: true,
|
|
439
|
-
operation: 'drop',
|
|
440
|
-
table: tableName,
|
|
441
|
-
executionTime: Date.now() - startTime,
|
|
442
|
-
};
|
|
575
|
+
await context.client.query('COMMIT');
|
|
576
|
+
context.client.release();
|
|
577
|
+
context.status = 'committed';
|
|
443
578
|
}
|
|
444
579
|
catch (error) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
table: tableName,
|
|
449
|
-
error: error.message,
|
|
450
|
-
executionTime: Date.now() - startTime,
|
|
451
|
-
};
|
|
580
|
+
context.status = 'error';
|
|
581
|
+
context.client.release();
|
|
582
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to commit transaction: ${error.message}`, error);
|
|
452
583
|
}
|
|
453
584
|
}
|
|
454
|
-
async
|
|
455
|
-
const startTime = Date.now();
|
|
585
|
+
async rollbackTransaction(context) {
|
|
456
586
|
try {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
await conn.query(query);
|
|
461
|
-
}
|
|
462
|
-
return {
|
|
463
|
-
success: true,
|
|
464
|
-
operation: 'alter',
|
|
465
|
-
table: tableName,
|
|
466
|
-
executionTime: Date.now() - startTime,
|
|
467
|
-
};
|
|
587
|
+
await context.client.query('ROLLBACK');
|
|
588
|
+
context.client.release();
|
|
589
|
+
context.status = 'rolled_back';
|
|
468
590
|
}
|
|
469
591
|
catch (error) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
table: tableName,
|
|
474
|
-
error: error.message,
|
|
475
|
-
executionTime: Date.now() - startTime,
|
|
476
|
-
};
|
|
592
|
+
context.status = 'error';
|
|
593
|
+
context.client.release();
|
|
594
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to rollback transaction: ${error.message}`, error);
|
|
477
595
|
}
|
|
478
596
|
}
|
|
479
|
-
async
|
|
597
|
+
async createSavepoint(context, name) {
|
|
480
598
|
try {
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
NUMERIC_SCALE as numeric_scale,
|
|
491
|
-
COLUMN_KEY as column_key
|
|
492
|
-
FROM INFORMATION_SCHEMA.COLUMNS
|
|
493
|
-
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?
|
|
494
|
-
ORDER BY ORDINAL_POSITION
|
|
495
|
-
`;
|
|
496
|
-
const [rows] = await conn.query(query, [tableName]);
|
|
497
|
-
const columns = rows.map((row) => ({
|
|
498
|
-
name: row.column_name,
|
|
499
|
-
type: this.mapMySQLTypeToColumnType(row.data_type),
|
|
500
|
-
nullable: row.is_nullable === 'YES',
|
|
501
|
-
primaryKey: row.column_key === 'PRI',
|
|
502
|
-
unique: row.column_key === 'UNI',
|
|
503
|
-
defaultValue: row.column_default,
|
|
504
|
-
length: row.character_maximum_length,
|
|
505
|
-
precision: row.numeric_precision,
|
|
506
|
-
scale: row.numeric_scale,
|
|
507
|
-
}));
|
|
508
|
-
return {
|
|
509
|
-
name: tableName,
|
|
510
|
-
columns,
|
|
599
|
+
await context.client.query(`SAVEPOINT ${this.escapeIdentifier(name)}`);
|
|
600
|
+
const savepoint = {
|
|
601
|
+
name,
|
|
602
|
+
release: async () => {
|
|
603
|
+
await this.releaseSavepoint(context, savepoint);
|
|
604
|
+
},
|
|
605
|
+
rollback: async () => {
|
|
606
|
+
await this.rollbackToSavepoint(context, savepoint);
|
|
607
|
+
},
|
|
511
608
|
};
|
|
609
|
+
context.savepoints.set(name, savepoint);
|
|
610
|
+
return savepoint;
|
|
512
611
|
}
|
|
513
612
|
catch (error) {
|
|
514
|
-
throw
|
|
613
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to create savepoint: ${error.message}`, error);
|
|
515
614
|
}
|
|
516
615
|
}
|
|
517
|
-
async
|
|
616
|
+
async releaseSavepoint(context, savepoint) {
|
|
518
617
|
try {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
return rows.map((row) => Object.values(row)[0]);
|
|
618
|
+
await context.client.query(`RELEASE SAVEPOINT ${this.escapeIdentifier(savepoint.name)}`);
|
|
619
|
+
context.savepoints.delete(savepoint.name);
|
|
522
620
|
}
|
|
523
621
|
catch (error) {
|
|
524
|
-
throw
|
|
622
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to release savepoint: ${error.message}`, error);
|
|
525
623
|
}
|
|
526
624
|
}
|
|
527
|
-
async
|
|
625
|
+
async rollbackToSavepoint(context, savepoint) {
|
|
528
626
|
try {
|
|
529
|
-
|
|
530
|
-
const query = `
|
|
531
|
-
SELECT COUNT(*) as count
|
|
532
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
533
|
-
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?
|
|
534
|
-
`;
|
|
535
|
-
const [rows] = await conn.query(query, [tableName]);
|
|
536
|
-
return rows[0].count > 0;
|
|
627
|
+
await context.client.query(`ROLLBACK TO SAVEPOINT ${this.escapeIdentifier(savepoint.name)}`);
|
|
537
628
|
}
|
|
538
629
|
catch (error) {
|
|
539
|
-
throw
|
|
630
|
+
throw database_error_1.DatabaseError.transactionError(`Failed to rollback to savepoint: ${error.message}`, error);
|
|
540
631
|
}
|
|
541
632
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const startTime = Date.now();
|
|
545
|
-
try {
|
|
546
|
-
const query = this.buildCreateIndexQuery(options);
|
|
547
|
-
const conn = connection.getClient();
|
|
548
|
-
await conn.query(query);
|
|
549
|
-
return {
|
|
550
|
-
success: true,
|
|
551
|
-
operation: 'create',
|
|
552
|
-
indexName: options.index.name,
|
|
553
|
-
table: options.table,
|
|
554
|
-
executionTime: Date.now() - startTime,
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
catch (error) {
|
|
558
|
-
return {
|
|
559
|
-
success: false,
|
|
560
|
-
operation: 'create',
|
|
561
|
-
indexName: options.index.name,
|
|
562
|
-
table: options.table,
|
|
563
|
-
error: error.message,
|
|
564
|
-
executionTime: Date.now() - startTime,
|
|
565
|
-
};
|
|
566
|
-
}
|
|
633
|
+
supportsSavepoints() {
|
|
634
|
+
return true;
|
|
567
635
|
}
|
|
568
|
-
|
|
569
|
-
|
|
636
|
+
// ==================== SCHEMA METHODS ====================
|
|
637
|
+
async createTable(definition, options) {
|
|
638
|
+
this.ensureConnected();
|
|
570
639
|
try {
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
640
|
+
const columnDefs = definition.columns.map(col => this.buildColumnDefinition(col)).join(', ');
|
|
641
|
+
let sql = 'CREATE';
|
|
642
|
+
if (options === null || options === void 0 ? void 0 : options.temporary)
|
|
643
|
+
sql += ' TEMPORARY';
|
|
644
|
+
sql += ' TABLE';
|
|
645
|
+
if (options === null || options === void 0 ? void 0 : options.ifNotExists)
|
|
646
|
+
sql += ' IF NOT EXISTS';
|
|
647
|
+
sql += ` ${this.escapeIdentifier(definition.name)} (${columnDefs}`;
|
|
648
|
+
// Add table constraints
|
|
649
|
+
if (definition.constraints) {
|
|
650
|
+
const constraintDefs = definition.constraints.map(c => this.buildConstraintDefinition(c)).join(', ');
|
|
651
|
+
sql += `, ${constraintDefs}`;
|
|
652
|
+
}
|
|
653
|
+
sql += ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
|
|
654
|
+
// Add table comment
|
|
655
|
+
if (definition.comment) {
|
|
656
|
+
sql += ` COMMENT=${this.escapeValue(definition.comment)}`;
|
|
657
|
+
}
|
|
658
|
+
await this.pool.query(sql);
|
|
659
|
+
// Create indexes
|
|
660
|
+
if (definition.indexes) {
|
|
661
|
+
for (const index of definition.indexes) {
|
|
662
|
+
await this.createIndex(index);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
580
665
|
}
|
|
581
666
|
catch (error) {
|
|
582
|
-
|
|
583
|
-
success: false,
|
|
584
|
-
operation: 'drop',
|
|
585
|
-
indexName: options.indexName,
|
|
586
|
-
table: options.table,
|
|
587
|
-
error: error.message,
|
|
588
|
-
executionTime: Date.now() - startTime,
|
|
589
|
-
};
|
|
667
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to create table: ${error.message}`, error);
|
|
590
668
|
}
|
|
591
669
|
}
|
|
592
|
-
async
|
|
670
|
+
async alterTable(tableName, operations) {
|
|
671
|
+
this.ensureConnected();
|
|
593
672
|
try {
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
673
|
+
for (const op of operations) {
|
|
674
|
+
let sql = `ALTER TABLE ${this.escapeIdentifier(tableName)}`;
|
|
675
|
+
switch (op.type) {
|
|
676
|
+
case 'ADD':
|
|
677
|
+
if (op.column) {
|
|
678
|
+
sql += ` ADD COLUMN ${this.buildColumnDefinition(op.column)}`;
|
|
679
|
+
}
|
|
680
|
+
else if (op.constraint) {
|
|
681
|
+
sql += ` ADD ${this.buildConstraintDefinition(op.constraint)}`;
|
|
682
|
+
}
|
|
683
|
+
break;
|
|
684
|
+
case 'DROP':
|
|
685
|
+
if (op.columnName) {
|
|
686
|
+
sql += ` DROP COLUMN ${this.escapeIdentifier(op.columnName)}`;
|
|
687
|
+
}
|
|
688
|
+
else if (op.constraintName) {
|
|
689
|
+
sql += ` DROP CONSTRAINT ${this.escapeIdentifier(op.constraintName)}`;
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
case 'MODIFY':
|
|
693
|
+
if (op.column) {
|
|
694
|
+
sql += ` MODIFY COLUMN ${this.buildColumnDefinition(op.column)}`;
|
|
695
|
+
}
|
|
696
|
+
break;
|
|
697
|
+
case 'RENAME':
|
|
698
|
+
if (op.oldName && op.newName) {
|
|
699
|
+
sql += ` RENAME COLUMN ${this.escapeIdentifier(op.oldName)} TO ${this.escapeIdentifier(op.newName)}`;
|
|
700
|
+
}
|
|
701
|
+
break;
|
|
618
702
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
indexInfo.columnDetails.push({
|
|
622
|
-
name: row.column_name,
|
|
623
|
-
order: 'ASC',
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
return Array.from(indexMap.values());
|
|
703
|
+
await this.pool.query(sql);
|
|
704
|
+
}
|
|
627
705
|
}
|
|
628
706
|
catch (error) {
|
|
629
|
-
throw
|
|
707
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to alter table: ${error.message}`, error);
|
|
630
708
|
}
|
|
631
709
|
}
|
|
632
|
-
async
|
|
710
|
+
async dropTable(tableName, ifExists, cascade) {
|
|
711
|
+
this.ensureConnected();
|
|
633
712
|
try {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?
|
|
641
|
-
`;
|
|
642
|
-
const params = [tableName];
|
|
643
|
-
if (indexName) {
|
|
644
|
-
query += ' AND INDEX_NAME = ?';
|
|
645
|
-
params.push(indexName);
|
|
646
|
-
}
|
|
647
|
-
const [rows] = await conn.query(query, params);
|
|
648
|
-
return rows.map((row) => ({
|
|
649
|
-
indexName: row.index_name,
|
|
650
|
-
table: tableName,
|
|
651
|
-
size: 0, // MySQL doesn't provide this easily
|
|
652
|
-
tuplesRead: row.cardinality || 0,
|
|
653
|
-
}));
|
|
713
|
+
let sql = 'DROP TABLE';
|
|
714
|
+
if (ifExists)
|
|
715
|
+
sql += ' IF EXISTS';
|
|
716
|
+
sql += ` ${this.escapeIdentifier(tableName)}`;
|
|
717
|
+
// MySQL doesn't support CASCADE in DROP TABLE
|
|
718
|
+
await this.pool.query(sql);
|
|
654
719
|
}
|
|
655
720
|
catch (error) {
|
|
656
|
-
throw
|
|
721
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to drop table: ${error.message}`, error);
|
|
657
722
|
}
|
|
658
723
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
* Build SQL for a migration operation
|
|
662
|
-
*/
|
|
663
|
-
async buildMigrationOperationSQL(operation) {
|
|
664
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
665
|
-
switch (operation.type) {
|
|
666
|
-
case migration_types_1.MigrationOperationType.RAW_SQL:
|
|
667
|
-
return operation.sql || null;
|
|
668
|
-
case migration_types_1.MigrationOperationType.CREATE_TABLE:
|
|
669
|
-
if ((_a = operation.params) === null || _a === void 0 ? void 0 : _a.schema) {
|
|
670
|
-
const schema = operation.params.schema;
|
|
671
|
-
const columns = schema.columns
|
|
672
|
-
.map((col) => {
|
|
673
|
-
let def = `\`${col.name}\` ${this.mapColumnTypeToMySQL(col.type)}`;
|
|
674
|
-
if (col.primaryKey)
|
|
675
|
-
def += ' PRIMARY KEY';
|
|
676
|
-
if (col.autoIncrement)
|
|
677
|
-
def += ' AUTO_INCREMENT';
|
|
678
|
-
if (!col.nullable)
|
|
679
|
-
def += ' NOT NULL';
|
|
680
|
-
if (col.unique)
|
|
681
|
-
def += ' UNIQUE';
|
|
682
|
-
if (col.defaultValue !== undefined) {
|
|
683
|
-
def += ` DEFAULT ${this.escapeValue(col.defaultValue)}`;
|
|
684
|
-
}
|
|
685
|
-
return def;
|
|
686
|
-
})
|
|
687
|
-
.join(', ');
|
|
688
|
-
return `CREATE TABLE \`${schema.name}\` (${columns})`;
|
|
689
|
-
}
|
|
690
|
-
return null;
|
|
691
|
-
case migration_types_1.MigrationOperationType.DROP_TABLE:
|
|
692
|
-
return operation.table ? `DROP TABLE IF EXISTS \`${operation.table}\`` : null;
|
|
693
|
-
case migration_types_1.MigrationOperationType.ADD_COLUMN:
|
|
694
|
-
if (operation.table && ((_b = operation.params) === null || _b === void 0 ? void 0 : _b.column)) {
|
|
695
|
-
const col = operation.params.column;
|
|
696
|
-
let def = `ALTER TABLE \`${operation.table}\` ADD COLUMN \`${col.name}\` ${this.mapColumnTypeToMySQL(col.type)}`;
|
|
697
|
-
if (!col.nullable)
|
|
698
|
-
def += ' NOT NULL';
|
|
699
|
-
if (col.defaultValue !== undefined) {
|
|
700
|
-
def += ` DEFAULT ${this.escapeValue(col.defaultValue)}`;
|
|
701
|
-
}
|
|
702
|
-
return def;
|
|
703
|
-
}
|
|
704
|
-
return null;
|
|
705
|
-
case migration_types_1.MigrationOperationType.DROP_COLUMN:
|
|
706
|
-
return operation.table && ((_c = operation.params) === null || _c === void 0 ? void 0 : _c.columnName)
|
|
707
|
-
? `ALTER TABLE \`${operation.table}\` DROP COLUMN \`${operation.params.columnName}\``
|
|
708
|
-
: null;
|
|
709
|
-
case migration_types_1.MigrationOperationType.MODIFY_COLUMN:
|
|
710
|
-
if (operation.table && ((_d = operation.params) === null || _d === void 0 ? void 0 : _d.column)) {
|
|
711
|
-
const col = operation.params.column;
|
|
712
|
-
return `ALTER TABLE \`${operation.table}\` MODIFY COLUMN \`${col.name}\` ${this.mapColumnTypeToMySQL(col.type)}`;
|
|
713
|
-
}
|
|
714
|
-
return null;
|
|
715
|
-
case migration_types_1.MigrationOperationType.RENAME_COLUMN:
|
|
716
|
-
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)
|
|
717
|
-
? `ALTER TABLE \`${operation.table}\` RENAME COLUMN \`${operation.params.oldName}\` TO \`${operation.params.newName}\``
|
|
718
|
-
: null;
|
|
719
|
-
case migration_types_1.MigrationOperationType.ADD_INDEX:
|
|
720
|
-
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)) {
|
|
721
|
-
const unique = operation.params.unique ? 'UNIQUE ' : '';
|
|
722
|
-
const columns = operation.params.columns.map((col) => `\`${col}\``).join(', ');
|
|
723
|
-
return `CREATE ${unique}INDEX \`${operation.params.indexName}\` ON \`${operation.table}\` (${columns})`;
|
|
724
|
-
}
|
|
725
|
-
return null;
|
|
726
|
-
case migration_types_1.MigrationOperationType.DROP_INDEX:
|
|
727
|
-
return ((_j = operation.params) === null || _j === void 0 ? void 0 : _j.indexName) && operation.table
|
|
728
|
-
? `DROP INDEX \`${operation.params.indexName}\` ON \`${operation.table}\``
|
|
729
|
-
: null;
|
|
730
|
-
case migration_types_1.MigrationOperationType.ADD_CONSTRAINT:
|
|
731
|
-
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)) {
|
|
732
|
-
return `ALTER TABLE \`${operation.table}\` ADD CONSTRAINT \`${operation.params.constraintName}\` ${operation.params.definition}`;
|
|
733
|
-
}
|
|
734
|
-
return null;
|
|
735
|
-
case migration_types_1.MigrationOperationType.DROP_CONSTRAINT:
|
|
736
|
-
return operation.table && ((_m = operation.params) === null || _m === void 0 ? void 0 : _m.constraintName)
|
|
737
|
-
? `ALTER TABLE \`${operation.table}\` DROP CONSTRAINT \`${operation.params.constraintName}\``
|
|
738
|
-
: null;
|
|
739
|
-
default:
|
|
740
|
-
return null;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
async runMigration(connection, migration, options) {
|
|
744
|
-
const startTime = Date.now();
|
|
745
|
-
const statements = [];
|
|
724
|
+
async listTables() {
|
|
725
|
+
this.ensureConnected();
|
|
746
726
|
try {
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
try {
|
|
750
|
-
// Execute migration operations
|
|
751
|
-
for (const operation of migration.up) {
|
|
752
|
-
const sql = await this.buildMigrationOperationSQL(operation);
|
|
753
|
-
if (sql) {
|
|
754
|
-
statements.push(sql);
|
|
755
|
-
await conn.query(sql);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
// Record migration in history table
|
|
759
|
-
await this.recordMigration(conn, migration, migration_types_1.MigrationDirection.UP);
|
|
760
|
-
await conn.query('COMMIT');
|
|
761
|
-
return {
|
|
762
|
-
tag: migration.tag,
|
|
763
|
-
status: migration_types_1.MigrationStatus.COMPLETED,
|
|
764
|
-
direction: migration_types_1.MigrationDirection.UP,
|
|
765
|
-
executedAt: new Date(),
|
|
766
|
-
duration: Date.now() - startTime,
|
|
767
|
-
statements,
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
catch (error) {
|
|
771
|
-
await conn.query('ROLLBACK');
|
|
772
|
-
throw error;
|
|
773
|
-
}
|
|
727
|
+
const [rows] = await this.pool.query('SHOW TABLES');
|
|
728
|
+
return rows.map((r) => Object.values(r)[0]);
|
|
774
729
|
}
|
|
775
730
|
catch (error) {
|
|
776
|
-
|
|
777
|
-
tag: migration.tag,
|
|
778
|
-
status: migration_types_1.MigrationStatus.FAILED,
|
|
779
|
-
direction: migration_types_1.MigrationDirection.UP,
|
|
780
|
-
executedAt: new Date(),
|
|
781
|
-
duration: Date.now() - startTime,
|
|
782
|
-
error: error.message,
|
|
783
|
-
statements,
|
|
784
|
-
};
|
|
731
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to list tables: ${error.message}`, error);
|
|
785
732
|
}
|
|
786
733
|
}
|
|
787
|
-
async
|
|
788
|
-
|
|
789
|
-
const statements = [];
|
|
734
|
+
async tableExists(tableName) {
|
|
735
|
+
this.ensureConnected();
|
|
790
736
|
try {
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
try {
|
|
794
|
-
// Execute rollback operations
|
|
795
|
-
for (const operation of migration.down) {
|
|
796
|
-
const sql = await this.buildMigrationOperationSQL(operation);
|
|
797
|
-
if (sql) {
|
|
798
|
-
statements.push(sql);
|
|
799
|
-
await conn.query(sql);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
// Remove migration from history table
|
|
803
|
-
await this.removeMigration(conn, migration.tag);
|
|
804
|
-
await conn.query('COMMIT');
|
|
805
|
-
return {
|
|
806
|
-
tag: migration.tag,
|
|
807
|
-
status: migration_types_1.MigrationStatus.ROLLED_BACK,
|
|
808
|
-
direction: migration_types_1.MigrationDirection.DOWN,
|
|
809
|
-
executedAt: new Date(),
|
|
810
|
-
duration: Date.now() - startTime,
|
|
811
|
-
statements,
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
catch (error) {
|
|
815
|
-
await conn.query('ROLLBACK');
|
|
816
|
-
throw error;
|
|
817
|
-
}
|
|
737
|
+
const [rows] = await this.pool.query(`SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?`, [tableName]);
|
|
738
|
+
return rows[0].count > 0;
|
|
818
739
|
}
|
|
819
740
|
catch (error) {
|
|
820
|
-
|
|
821
|
-
tag: migration.tag,
|
|
822
|
-
status: migration_types_1.MigrationStatus.FAILED,
|
|
823
|
-
direction: migration_types_1.MigrationDirection.DOWN,
|
|
824
|
-
executedAt: new Date(),
|
|
825
|
-
duration: Date.now() - startTime,
|
|
826
|
-
error: error.message,
|
|
827
|
-
statements,
|
|
828
|
-
};
|
|
741
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to check table existence: ${error.message}`, error);
|
|
829
742
|
}
|
|
830
743
|
}
|
|
831
|
-
async
|
|
744
|
+
async getTableSchema(tableName) {
|
|
745
|
+
this.ensureConnected();
|
|
832
746
|
try {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
747
|
+
// Get columns
|
|
748
|
+
const [columns] = await this.pool.query(`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
|
+
COLUMN_KEY = 'PRI' as is_primary_key,
|
|
757
|
+
COLUMN_KEY = 'UNI' as is_unique,
|
|
758
|
+
EXTRA LIKE '%auto_increment%' as is_auto_increment,
|
|
759
|
+
COLUMN_COMMENT as comment
|
|
760
|
+
FROM information_schema.columns
|
|
761
|
+
WHERE table_schema = DATABASE() AND table_name = ?
|
|
762
|
+
ORDER BY ordinal_position`, [tableName]);
|
|
763
|
+
// Get primary key
|
|
764
|
+
const primaryKey = columns
|
|
765
|
+
.filter((c) => c.is_primary_key)
|
|
766
|
+
.map((c) => c.name);
|
|
767
|
+
// Get indexes
|
|
768
|
+
const indexes = await this.listIndexes(tableName);
|
|
769
|
+
// Get constraints
|
|
770
|
+
const [constraintRows] = await this.pool.query(`SELECT
|
|
771
|
+
CONSTRAINT_NAME as name,
|
|
772
|
+
CONSTRAINT_TYPE as type
|
|
773
|
+
FROM information_schema.table_constraints
|
|
774
|
+
WHERE table_schema = DATABASE() AND table_name = ?`, [tableName]);
|
|
775
|
+
const columnInfos = columns.map((col) => ({
|
|
776
|
+
name: col.name,
|
|
777
|
+
type: col.type,
|
|
778
|
+
nullable: !!col.nullable,
|
|
779
|
+
defaultValue: col.default_value,
|
|
780
|
+
isPrimaryKey: !!col.is_primary_key,
|
|
781
|
+
isUnique: !!col.is_unique,
|
|
782
|
+
isAutoIncrement: !!col.is_auto_increment,
|
|
783
|
+
maxLength: col.max_length,
|
|
784
|
+
precision: col.precision,
|
|
785
|
+
scale: col.scale,
|
|
786
|
+
comment: col.comment || undefined,
|
|
851
787
|
}));
|
|
788
|
+
const constraints = constraintRows.map((c) => ({
|
|
789
|
+
name: c.name,
|
|
790
|
+
type: c.type,
|
|
791
|
+
columns: [], // Would need additional query to get columns
|
|
792
|
+
}));
|
|
793
|
+
return {
|
|
794
|
+
name: tableName,
|
|
795
|
+
columns: columnInfos,
|
|
796
|
+
indexes,
|
|
797
|
+
constraints,
|
|
798
|
+
primaryKey: primaryKey.length > 0 ? primaryKey : undefined,
|
|
799
|
+
};
|
|
852
800
|
}
|
|
853
801
|
catch (error) {
|
|
854
|
-
throw
|
|
802
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to get table schema: ${error.message}`, error);
|
|
855
803
|
}
|
|
856
804
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
let selectColumns;
|
|
867
|
-
if (options.select) {
|
|
868
|
-
const cols = Array.isArray(options.select) ? options.select : [options.select];
|
|
869
|
-
// Prefix main table columns with table name
|
|
870
|
-
selectColumns = cols.map((col) => `\`${options.table}\`.\`${col}\``).join(', ');
|
|
871
|
-
}
|
|
872
|
-
else {
|
|
873
|
-
// Select all from main table
|
|
874
|
-
selectColumns = hasIncludes ? `\`${options.table}\`.*` : '*';
|
|
875
|
-
}
|
|
876
|
-
// Add included relation columns
|
|
877
|
-
if (hasIncludes) {
|
|
878
|
-
const includes = Array.isArray(options.include) ? options.include : [options.include];
|
|
879
|
-
includes.forEach((include) => {
|
|
880
|
-
const relationAlias = include.relation;
|
|
881
|
-
if (include.select && include.select.length > 0) {
|
|
882
|
-
const relationCols = include.select.map((col) => `\`${relationAlias}\`.\`${col}\` as \`${relationAlias}_${col}\``).join(', ');
|
|
883
|
-
selectColumns += `, ${relationCols}`;
|
|
884
|
-
}
|
|
885
|
-
else {
|
|
886
|
-
// Use JSON aggregation for one-to-many
|
|
887
|
-
if (include.type === 'one-to-many') {
|
|
888
|
-
selectColumns += `, JSON_ARRAYAGG(JSON_OBJECT('*', \`${relationAlias}\`.*)) as \`${relationAlias}\``;
|
|
889
|
-
}
|
|
890
|
-
else {
|
|
891
|
-
selectColumns += `, JSON_OBJECT('*', \`${relationAlias}\`.*) as \`${relationAlias}\``;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
let query = `SELECT ${options.distinct ? 'DISTINCT ' : ''}${selectColumns} FROM \`${options.table}\``;
|
|
897
|
-
// JOIN clauses for includes
|
|
898
|
-
if (hasIncludes) {
|
|
899
|
-
const includes = Array.isArray(options.include) ? options.include : [options.include];
|
|
900
|
-
includes.forEach((include) => {
|
|
901
|
-
const { joinClause } = this.buildIncludeJoin(options.table, include);
|
|
902
|
-
query += ` ${joinClause}`;
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
// WHERE clause
|
|
906
|
-
if (options.where) {
|
|
907
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
908
|
-
query += ` WHERE ${clause}`;
|
|
909
|
-
params.push(...values);
|
|
910
|
-
}
|
|
911
|
-
// GROUP BY clause
|
|
912
|
-
if (options.groupBy && options.groupBy.length > 0) {
|
|
913
|
-
query += ` GROUP BY ${options.groupBy.map((col) => `\`${col}\``).join(', ')}`;
|
|
914
|
-
}
|
|
915
|
-
else if (hasIncludes) {
|
|
916
|
-
// Auto group by main table primary key for one-to-many relations
|
|
917
|
-
const includes = Array.isArray(options.include) ? options.include : [options.include];
|
|
918
|
-
const hasOneToMany = includes.some(inc => inc.type === 'one-to-many');
|
|
919
|
-
if (hasOneToMany) {
|
|
920
|
-
query += ` GROUP BY \`${options.table}\`.\`id\``;
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
// HAVING clause
|
|
924
|
-
if (options.having) {
|
|
925
|
-
const { clause, values } = this.buildWhereClause(options.having);
|
|
926
|
-
query += ` HAVING ${clause}`;
|
|
927
|
-
params.push(...values);
|
|
928
|
-
}
|
|
929
|
-
// ORDER BY clause
|
|
930
|
-
if (options.orderBy) {
|
|
931
|
-
const orderByArray = Array.isArray(options.orderBy) ? options.orderBy : [options.orderBy];
|
|
932
|
-
const orderClauses = orderByArray.map((order) => `\`${options.table}\`.\`${order.column}\` ${order.order || 'ASC'}`);
|
|
933
|
-
query += ` ORDER BY ${orderClauses.join(', ')}`;
|
|
934
|
-
}
|
|
935
|
-
// LIMIT clause
|
|
936
|
-
if (options.limit) {
|
|
937
|
-
query += ` LIMIT ?`;
|
|
938
|
-
params.push(options.limit);
|
|
939
|
-
}
|
|
940
|
-
// OFFSET clause
|
|
941
|
-
if (options.offset) {
|
|
942
|
-
query += ` OFFSET ?`;
|
|
943
|
-
params.push(options.offset);
|
|
944
|
-
}
|
|
945
|
-
return { query, params };
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Build JOIN clause for include relationships
|
|
949
|
-
*/
|
|
950
|
-
buildIncludeJoin(mainTable, include) {
|
|
951
|
-
const relationTable = include.relation;
|
|
952
|
-
const foreignKey = include.foreignKey || `${relationTable}_id`;
|
|
953
|
-
const primaryKey = include.primaryKey || 'id';
|
|
954
|
-
const joinType = include.type === 'one-to-many' || include.type === 'one-to-one' ? 'LEFT' : 'INNER';
|
|
955
|
-
let joinClause;
|
|
956
|
-
if (include.type === 'many-to-many' && include.through) {
|
|
957
|
-
// Many-to-many with junction table
|
|
958
|
-
const throughTable = include.through;
|
|
959
|
-
const throughForeignKey = include.throughForeignKey || `${mainTable}_id`;
|
|
960
|
-
const throughRelatedKey = include.throughRelatedKey || `${relationTable}_id`;
|
|
961
|
-
joinClause = `${joinType} JOIN \`${throughTable}\` ON \`${mainTable}\`.\`${primaryKey}\` = \`${throughTable}\`.\`${throughForeignKey}\` `;
|
|
962
|
-
joinClause += `${joinType} JOIN \`${relationTable}\` ON \`${throughTable}\`.\`${throughRelatedKey}\` = \`${relationTable}\`.\`${primaryKey}\``;
|
|
963
|
-
}
|
|
964
|
-
else if (include.type === 'one-to-many') {
|
|
965
|
-
// One-to-many: foreign key is in the related table
|
|
966
|
-
joinClause = `${joinType} JOIN \`${relationTable}\` ON \`${mainTable}\`.\`${primaryKey}\` = \`${relationTable}\`.\`${foreignKey}\``;
|
|
967
|
-
}
|
|
968
|
-
else {
|
|
969
|
-
// Many-to-one or one-to-one: foreign key is in the main table
|
|
970
|
-
joinClause = `${joinType} JOIN \`${relationTable}\` ON \`${mainTable}\`.\`${foreignKey}\` = \`${relationTable}\`.\`${primaryKey}\``;
|
|
971
|
-
}
|
|
972
|
-
// Add where clause for the relation if specified
|
|
973
|
-
if (include.where) {
|
|
974
|
-
const { clause } = this.buildWhereClause(include.where);
|
|
975
|
-
joinClause += ` AND ${clause}`;
|
|
976
|
-
}
|
|
977
|
-
return { joinClause };
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* Build WHERE clause from options
|
|
981
|
-
* Supports both simplified syntax (GT, LT, AND, OR) and legacy syntax ($gt, $lt, $and, $or)
|
|
982
|
-
*/
|
|
983
|
-
buildWhereClause(where) {
|
|
984
|
-
const values = [];
|
|
985
|
-
const buildCondition = (condition) => {
|
|
986
|
-
if (typeof condition !== 'object' || condition === null) {
|
|
987
|
-
values.push(condition);
|
|
988
|
-
return '?';
|
|
805
|
+
async createIndex(index, ifNotExists, concurrent) {
|
|
806
|
+
this.ensureConnected();
|
|
807
|
+
try {
|
|
808
|
+
let sql = 'CREATE';
|
|
809
|
+
if (index.unique)
|
|
810
|
+
sql += ' UNIQUE';
|
|
811
|
+
// Index type for MySQL
|
|
812
|
+
if (index.method === 'FULLTEXT') {
|
|
813
|
+
sql += ' FULLTEXT';
|
|
989
814
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
const andConditions = condition.$AND || condition.AND || condition.$and;
|
|
993
|
-
if (typeof andConditions === 'object' && !Array.isArray(andConditions)) {
|
|
994
|
-
// New syntax: { $AND: { col1: val1, col2: val2 } }
|
|
995
|
-
return buildCondition(andConditions);
|
|
996
|
-
}
|
|
997
|
-
else {
|
|
998
|
-
// Legacy syntax: { $and: [cond1, cond2] }
|
|
999
|
-
const subConditions = andConditions.map(buildCondition);
|
|
1000
|
-
return `(${subConditions.join(' AND ')})`;
|
|
1001
|
-
}
|
|
815
|
+
else if (index.method === 'SPATIAL') {
|
|
816
|
+
sql += ' SPATIAL';
|
|
1002
817
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
return `(${subClauses.join(' OR ')})`;
|
|
1017
|
-
}
|
|
1018
|
-
else {
|
|
1019
|
-
// Legacy syntax: { $or: [cond1, cond2] }
|
|
1020
|
-
const subConditions = orConditions.map(buildCondition);
|
|
1021
|
-
return `(${subConditions.join(' OR ')})`;
|
|
1022
|
-
}
|
|
818
|
+
sql += ' INDEX';
|
|
819
|
+
sql += ` ${this.escapeIdentifier(index.name)} ON ${this.escapeIdentifier(index.table)}`;
|
|
820
|
+
// Add columns
|
|
821
|
+
const columnDefs = index.columns.map(col => {
|
|
822
|
+
let def = this.escapeIdentifier(col.name);
|
|
823
|
+
if (col.order)
|
|
824
|
+
def += ` ${col.order}`;
|
|
825
|
+
return def;
|
|
826
|
+
}).join(', ');
|
|
827
|
+
sql += ` (${columnDefs})`;
|
|
828
|
+
// Add index type (BTREE, HASH)
|
|
829
|
+
if (index.method && !['FULLTEXT', 'SPATIAL'].includes(index.method)) {
|
|
830
|
+
sql += ` USING ${index.method}`;
|
|
1023
831
|
}
|
|
1024
|
-
//
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
// Skip logical operators
|
|
1028
|
-
if (key === '$AND' || key === 'AND' || key === '$and' || key === '$OR' || key === 'OR' || key === '$or') {
|
|
1029
|
-
continue;
|
|
1030
|
-
}
|
|
1031
|
-
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
1032
|
-
// Handle comparison operators
|
|
1033
|
-
for (const [op, opValue] of Object.entries(value)) {
|
|
1034
|
-
switch (op) {
|
|
1035
|
-
// Preferred $-prefixed syntax
|
|
1036
|
-
case '$GT':
|
|
1037
|
-
case 'GT':
|
|
1038
|
-
case '$gt':
|
|
1039
|
-
values.push(opValue);
|
|
1040
|
-
conditions.push(`\`${key}\` > ?`);
|
|
1041
|
-
break;
|
|
1042
|
-
case '$GTE':
|
|
1043
|
-
case 'GTE':
|
|
1044
|
-
case '$gte':
|
|
1045
|
-
values.push(opValue);
|
|
1046
|
-
conditions.push(`\`${key}\` >= ?`);
|
|
1047
|
-
break;
|
|
1048
|
-
case '$LT':
|
|
1049
|
-
case 'LT':
|
|
1050
|
-
case '$lt':
|
|
1051
|
-
values.push(opValue);
|
|
1052
|
-
conditions.push(`\`${key}\` < ?`);
|
|
1053
|
-
break;
|
|
1054
|
-
case '$LTE':
|
|
1055
|
-
case 'LTE':
|
|
1056
|
-
case '$lte':
|
|
1057
|
-
values.push(opValue);
|
|
1058
|
-
conditions.push(`\`${key}\` <= ?`);
|
|
1059
|
-
break;
|
|
1060
|
-
case '$NE':
|
|
1061
|
-
case '$NOT':
|
|
1062
|
-
case 'NE':
|
|
1063
|
-
case 'NOT':
|
|
1064
|
-
case '$ne':
|
|
1065
|
-
values.push(opValue);
|
|
1066
|
-
conditions.push(`\`${key}\` != ?`);
|
|
1067
|
-
break;
|
|
1068
|
-
case '$IN':
|
|
1069
|
-
case 'IN':
|
|
1070
|
-
case '$in':
|
|
1071
|
-
if (Array.isArray(opValue)) {
|
|
1072
|
-
const placeholders = opValue.map(() => '?').join(', ');
|
|
1073
|
-
values.push(...opValue);
|
|
1074
|
-
conditions.push(`\`${key}\` IN (${placeholders})`);
|
|
1075
|
-
}
|
|
1076
|
-
break;
|
|
1077
|
-
case '$NOT_IN':
|
|
1078
|
-
case 'NOT_IN':
|
|
1079
|
-
case '$nin':
|
|
1080
|
-
if (Array.isArray(opValue)) {
|
|
1081
|
-
const placeholders = opValue.map(() => '?').join(', ');
|
|
1082
|
-
values.push(...opValue);
|
|
1083
|
-
conditions.push(`\`${key}\` NOT IN (${placeholders})`);
|
|
1084
|
-
}
|
|
1085
|
-
break;
|
|
1086
|
-
case '$LIKE':
|
|
1087
|
-
case 'LIKE':
|
|
1088
|
-
case '$like':
|
|
1089
|
-
values.push(opValue);
|
|
1090
|
-
conditions.push(`\`${key}\` LIKE ?`);
|
|
1091
|
-
break;
|
|
1092
|
-
case '$IS_NULL':
|
|
1093
|
-
case 'IS_NULL':
|
|
1094
|
-
case '$null':
|
|
1095
|
-
conditions.push(`\`${key}\` IS NULL`);
|
|
1096
|
-
break;
|
|
1097
|
-
case '$IS_NOT_NULL':
|
|
1098
|
-
case 'IS_NOT_NULL':
|
|
1099
|
-
case '$notNull':
|
|
1100
|
-
conditions.push(`\`${key}\` IS NOT NULL`);
|
|
1101
|
-
break;
|
|
1102
|
-
case '$BETWEEN':
|
|
1103
|
-
case 'BETWEEN':
|
|
1104
|
-
case '$between':
|
|
1105
|
-
if (Array.isArray(opValue) && opValue.length === 2) {
|
|
1106
|
-
values.push(opValue[0], opValue[1]);
|
|
1107
|
-
conditions.push(`\`${key}\` BETWEEN ? AND ?`);
|
|
1108
|
-
}
|
|
1109
|
-
break;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
else {
|
|
1114
|
-
// Simple equality
|
|
1115
|
-
values.push(value);
|
|
1116
|
-
conditions.push(`\`${key}\` = ?`);
|
|
1117
|
-
}
|
|
832
|
+
// Add comment
|
|
833
|
+
if (index.comment) {
|
|
834
|
+
sql += ` COMMENT ${this.escapeValue(index.comment)}`;
|
|
1118
835
|
}
|
|
1119
|
-
|
|
1120
|
-
};
|
|
1121
|
-
const clause = buildCondition(where);
|
|
1122
|
-
return { clause, values };
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Build COUNT query
|
|
1126
|
-
*/
|
|
1127
|
-
buildCountQuery(options) {
|
|
1128
|
-
const params = [];
|
|
1129
|
-
const column = options.column ? `\`${options.column}\`` : '*';
|
|
1130
|
-
let query = `SELECT COUNT(${column}) as count FROM \`${options.table}\``;
|
|
1131
|
-
if (options.where) {
|
|
1132
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
1133
|
-
query += ` WHERE ${clause}`;
|
|
1134
|
-
params.push(...values);
|
|
1135
|
-
}
|
|
1136
|
-
return { query, params };
|
|
1137
|
-
}
|
|
1138
|
-
/**
|
|
1139
|
-
* Build aggregate query
|
|
1140
|
-
*/
|
|
1141
|
-
buildAggregateQuery(fn, column, options) {
|
|
1142
|
-
const params = [];
|
|
1143
|
-
let query = `SELECT ${fn}(\`${column}\`) as result FROM \`${options.table}\``;
|
|
1144
|
-
if (options.where) {
|
|
1145
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
1146
|
-
query += ` WHERE ${clause}`;
|
|
1147
|
-
params.push(...values);
|
|
836
|
+
await this.pool.query(sql);
|
|
1148
837
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
/**
|
|
1152
|
-
* Build INSERT query
|
|
1153
|
-
*/
|
|
1154
|
-
buildInsertQuery(options) {
|
|
1155
|
-
const dataArray = Array.isArray(options.data) ? options.data : [options.data];
|
|
1156
|
-
const columns = Object.keys(dataArray[0]);
|
|
1157
|
-
const params = [];
|
|
1158
|
-
let query = `INSERT INTO \`${options.table}\` (${columns.map((col) => `\`${col}\``).join(', ')}) VALUES `;
|
|
1159
|
-
const valuesClauses = dataArray.map((data) => {
|
|
1160
|
-
const placeholders = columns.map(() => '?');
|
|
1161
|
-
params.push(...columns.map((col) => data[col]));
|
|
1162
|
-
return `(${placeholders.join(', ')})`;
|
|
1163
|
-
});
|
|
1164
|
-
query += valuesClauses.join(', ');
|
|
1165
|
-
return { query, params };
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Build UPDATE query
|
|
1169
|
-
*/
|
|
1170
|
-
buildUpdateQuery(options) {
|
|
1171
|
-
const params = [];
|
|
1172
|
-
const setClauses = Object.keys(options.data).map((key) => {
|
|
1173
|
-
params.push(options.data[key]);
|
|
1174
|
-
return `\`${key}\` = ?`;
|
|
1175
|
-
});
|
|
1176
|
-
let query = `UPDATE \`${options.table}\` SET ${setClauses.join(', ')}`;
|
|
1177
|
-
if (options.where) {
|
|
1178
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
1179
|
-
query += ` WHERE ${clause}`;
|
|
1180
|
-
params.push(...values);
|
|
1181
|
-
}
|
|
1182
|
-
return { query, params };
|
|
1183
|
-
}
|
|
1184
|
-
/**
|
|
1185
|
-
* Build DELETE query
|
|
1186
|
-
*/
|
|
1187
|
-
buildDeleteQuery(options) {
|
|
1188
|
-
const params = [];
|
|
1189
|
-
let query = `DELETE FROM \`${options.table}\``;
|
|
1190
|
-
if (options.where) {
|
|
1191
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
1192
|
-
query += ` WHERE ${clause}`;
|
|
1193
|
-
params.push(...values);
|
|
838
|
+
catch (error) {
|
|
839
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to create index: ${error.message}`, error);
|
|
1194
840
|
}
|
|
1195
|
-
return { query, params };
|
|
1196
841
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
const columns = Object.keys(data);
|
|
1203
|
-
const params = [];
|
|
1204
|
-
let query = `INSERT INTO \`${options.table}\` (${columns.map((col) => `\`${col}\``).join(', ')}) VALUES (`;
|
|
1205
|
-
query += columns.map(() => '?').join(', ');
|
|
1206
|
-
params.push(...columns.map((col) => data[col]));
|
|
1207
|
-
query += ') ON DUPLICATE KEY UPDATE ';
|
|
1208
|
-
const updateClauses = columns
|
|
1209
|
-
.filter((col) => !options.uniqueColumns.includes(col))
|
|
1210
|
-
.map((col) => `\`${col}\` = VALUES(\`${col}\`)`);
|
|
1211
|
-
query += updateClauses.join(', ');
|
|
1212
|
-
return { query, params };
|
|
1213
|
-
}
|
|
1214
|
-
/**
|
|
1215
|
-
* Build GROUP BY query
|
|
1216
|
-
*/
|
|
1217
|
-
buildGroupByQuery(options) {
|
|
1218
|
-
const params = [];
|
|
1219
|
-
const groupColumns = options.groupBy.map((col) => `\`${col}\``);
|
|
1220
|
-
const selectColumns = [...groupColumns];
|
|
1221
|
-
// Build aggregations
|
|
1222
|
-
if (options.aggregate) {
|
|
1223
|
-
Object.entries(options.aggregate).forEach(([alias, agg]) => {
|
|
1224
|
-
const aggObj = agg;
|
|
1225
|
-
if (aggObj.$COUNT !== undefined) {
|
|
1226
|
-
const column = aggObj.$COUNT === '*' ? '*' : `\`${aggObj.$COUNT}\``;
|
|
1227
|
-
selectColumns.push(`COUNT(${column}) as \`${alias}\``);
|
|
1228
|
-
}
|
|
1229
|
-
else if (aggObj.$SUM !== undefined) {
|
|
1230
|
-
selectColumns.push(`SUM(\`${aggObj.$SUM}\`) as \`${alias}\``);
|
|
1231
|
-
}
|
|
1232
|
-
else if (aggObj.$AVG !== undefined) {
|
|
1233
|
-
selectColumns.push(`AVG(\`${aggObj.$AVG}\`) as \`${alias}\``);
|
|
1234
|
-
}
|
|
1235
|
-
else if (aggObj.$MIN !== undefined) {
|
|
1236
|
-
selectColumns.push(`MIN(\`${aggObj.$MIN}\`) as \`${alias}\``);
|
|
1237
|
-
}
|
|
1238
|
-
else if (aggObj.$MAX !== undefined) {
|
|
1239
|
-
selectColumns.push(`MAX(\`${aggObj.$MAX}\`) as \`${alias}\``);
|
|
1240
|
-
}
|
|
1241
|
-
else if (aggObj.$GROUP_CONCAT !== undefined) {
|
|
1242
|
-
selectColumns.push(`GROUP_CONCAT(\`${aggObj.$GROUP_CONCAT}\`) as \`${alias}\``);
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
842
|
+
async dropIndex(tableName, indexName, ifExists, concurrent, cascade) {
|
|
843
|
+
this.ensureConnected();
|
|
844
|
+
try {
|
|
845
|
+
let sql = `DROP INDEX ${this.escapeIdentifier(indexName)} ON ${this.escapeIdentifier(tableName)}`;
|
|
846
|
+
await this.pool.query(sql);
|
|
1245
847
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
1249
|
-
query += ` WHERE ${clause}`;
|
|
1250
|
-
params.push(...values);
|
|
848
|
+
catch (error) {
|
|
849
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to drop index: ${error.message}`, error);
|
|
1251
850
|
}
|
|
1252
|
-
query += ` GROUP BY ${groupColumns.join(', ')}`;
|
|
1253
|
-
return { query, params };
|
|
1254
851
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
const
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
}
|
|
1275
|
-
if (aggObj.$MAX !== undefined) {
|
|
1276
|
-
return `MAX(\`${aggObj.$MAX}\`) as \`${alias}\``;
|
|
1277
|
-
}
|
|
1278
|
-
if (aggObj.$GROUP_CONCAT !== undefined) {
|
|
1279
|
-
return `GROUP_CONCAT(\`${aggObj.$GROUP_CONCAT}\`) as \`${alias}\``;
|
|
1280
|
-
}
|
|
1281
|
-
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.VALIDATION_ERROR, `Invalid aggregation operation for alias "${alias}". Use format: { $COUNT: '*' }, { $SUM: 'column' }, etc.`);
|
|
1282
|
-
});
|
|
1283
|
-
let query = `SELECT ${aggregations.join(', ')} FROM \`${options.table}\``;
|
|
1284
|
-
if (options.where) {
|
|
1285
|
-
const { clause, values } = this.buildWhereClause(options.where);
|
|
1286
|
-
query += ` WHERE ${clause}`;
|
|
1287
|
-
params.push(...values);
|
|
1288
|
-
}
|
|
1289
|
-
return { query, params };
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Build CREATE TABLE query
|
|
1293
|
-
*/
|
|
1294
|
-
buildCreateTableQuery(schema, options) {
|
|
1295
|
-
const columnDefs = schema.columns.map((col) => {
|
|
1296
|
-
let def = `\`${col.name}\` ${this.mapColumnTypeToMySQL(col.type)}`;
|
|
1297
|
-
if (col.length) {
|
|
1298
|
-
def += `(${col.length})`;
|
|
1299
|
-
}
|
|
1300
|
-
if (col.primaryKey) {
|
|
1301
|
-
def += ' PRIMARY KEY';
|
|
1302
|
-
}
|
|
1303
|
-
if (col.autoIncrement) {
|
|
1304
|
-
def += ' AUTO_INCREMENT';
|
|
1305
|
-
}
|
|
1306
|
-
if (!col.nullable) {
|
|
1307
|
-
def += ' NOT NULL';
|
|
1308
|
-
}
|
|
1309
|
-
if (col.unique) {
|
|
1310
|
-
def += ' UNIQUE';
|
|
1311
|
-
}
|
|
1312
|
-
if (col.defaultValue !== undefined) {
|
|
1313
|
-
def += ` DEFAULT ${this.escapeValue(col.defaultValue)}`;
|
|
852
|
+
async listIndexes(tableName, includeSystem) {
|
|
853
|
+
this.ensureConnected();
|
|
854
|
+
try {
|
|
855
|
+
const [rows] = await this.pool.query(`SHOW INDEX FROM ${this.escapeIdentifier(tableName)}`);
|
|
856
|
+
// Group by index name
|
|
857
|
+
const indexMap = new Map();
|
|
858
|
+
for (const row of rows) {
|
|
859
|
+
const indexName = row.Key_name;
|
|
860
|
+
if (!indexMap.has(indexName)) {
|
|
861
|
+
indexMap.set(indexName, {
|
|
862
|
+
name: indexName,
|
|
863
|
+
table: tableName,
|
|
864
|
+
columns: [],
|
|
865
|
+
unique: !row.Non_unique,
|
|
866
|
+
primaryKey: indexName === 'PRIMARY',
|
|
867
|
+
type: row.Index_type,
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
indexMap.get(indexName).columns.push(row.Column_name);
|
|
1314
871
|
}
|
|
1315
|
-
return
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
|
|
872
|
+
return Array.from(indexMap.values());
|
|
873
|
+
}
|
|
874
|
+
catch (error) {
|
|
875
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to list indexes: ${error.message}`, error);
|
|
876
|
+
}
|
|
1319
877
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
break;
|
|
1336
|
-
case schema_types_1.ColumnAlterationType.MODIFY:
|
|
1337
|
-
query += `MODIFY COLUMN \`${alt.column.name}\` ${this.mapColumnTypeToMySQL(alt.column.type)}`;
|
|
1338
|
-
break;
|
|
1339
|
-
case schema_types_1.ColumnAlterationType.RENAME:
|
|
1340
|
-
query += `RENAME COLUMN \`${alt.oldName}\` TO \`${alt.newName}\``;
|
|
1341
|
-
break;
|
|
878
|
+
async getIndexStatistics(tableName, indexName) {
|
|
879
|
+
this.ensureConnected();
|
|
880
|
+
try {
|
|
881
|
+
let sql = `
|
|
882
|
+
SELECT
|
|
883
|
+
index_name,
|
|
884
|
+
table_name,
|
|
885
|
+
stat_value * @@innodb_page_size as size_bytes
|
|
886
|
+
FROM mysql.innodb_index_stats
|
|
887
|
+
WHERE database_name = DATABASE() AND table_name = ? AND stat_name = 'size'
|
|
888
|
+
`;
|
|
889
|
+
const params = [tableName];
|
|
890
|
+
if (indexName) {
|
|
891
|
+
sql += ` AND index_name = ?`;
|
|
892
|
+
params.push(indexName);
|
|
1342
893
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
*/
|
|
1357
|
-
mapColumnTypeToMySQL(type) {
|
|
1358
|
-
const typeMap = {
|
|
1359
|
-
[schema_types_1.ColumnType.STRING]: 'VARCHAR',
|
|
1360
|
-
[schema_types_1.ColumnType.TEXT]: 'TEXT',
|
|
1361
|
-
[schema_types_1.ColumnType.VARCHAR]: 'VARCHAR',
|
|
1362
|
-
[schema_types_1.ColumnType.CHAR]: 'CHAR',
|
|
1363
|
-
[schema_types_1.ColumnType.INTEGER]: 'INT',
|
|
1364
|
-
[schema_types_1.ColumnType.BIGINT]: 'BIGINT',
|
|
1365
|
-
[schema_types_1.ColumnType.SMALLINT]: 'SMALLINT',
|
|
1366
|
-
[schema_types_1.ColumnType.DECIMAL]: 'DECIMAL',
|
|
1367
|
-
[schema_types_1.ColumnType.NUMERIC]: 'DECIMAL',
|
|
1368
|
-
[schema_types_1.ColumnType.FLOAT]: 'FLOAT',
|
|
1369
|
-
[schema_types_1.ColumnType.DOUBLE]: 'DOUBLE',
|
|
1370
|
-
[schema_types_1.ColumnType.REAL]: 'FLOAT',
|
|
1371
|
-
[schema_types_1.ColumnType.BOOLEAN]: 'TINYINT',
|
|
1372
|
-
[schema_types_1.ColumnType.DATE]: 'DATE',
|
|
1373
|
-
[schema_types_1.ColumnType.TIME]: 'TIME',
|
|
1374
|
-
[schema_types_1.ColumnType.DATETIME]: 'DATETIME',
|
|
1375
|
-
[schema_types_1.ColumnType.TIMESTAMP]: 'TIMESTAMP',
|
|
1376
|
-
[schema_types_1.ColumnType.JSON]: 'JSON',
|
|
1377
|
-
[schema_types_1.ColumnType.JSONB]: 'JSON',
|
|
1378
|
-
[schema_types_1.ColumnType.UUID]: 'CHAR(36)',
|
|
1379
|
-
[schema_types_1.ColumnType.BLOB]: 'BLOB',
|
|
1380
|
-
[schema_types_1.ColumnType.BINARY]: 'BINARY',
|
|
1381
|
-
[schema_types_1.ColumnType.ARRAY]: 'JSON',
|
|
1382
|
-
[schema_types_1.ColumnType.OBJECT]: 'JSON',
|
|
1383
|
-
[schema_types_1.ColumnType.ENUM]: 'VARCHAR',
|
|
1384
|
-
};
|
|
1385
|
-
return typeMap[type] || 'TEXT';
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Map MySQL type to ColumnType
|
|
1389
|
-
*/
|
|
1390
|
-
mapMySQLTypeToColumnType(mysqlType) {
|
|
1391
|
-
const typeMap = {
|
|
1392
|
-
varchar: schema_types_1.ColumnType.VARCHAR,
|
|
1393
|
-
text: schema_types_1.ColumnType.TEXT,
|
|
1394
|
-
char: schema_types_1.ColumnType.CHAR,
|
|
1395
|
-
int: schema_types_1.ColumnType.INTEGER,
|
|
1396
|
-
bigint: schema_types_1.ColumnType.BIGINT,
|
|
1397
|
-
smallint: schema_types_1.ColumnType.SMALLINT,
|
|
1398
|
-
decimal: schema_types_1.ColumnType.DECIMAL,
|
|
1399
|
-
float: schema_types_1.ColumnType.FLOAT,
|
|
1400
|
-
double: schema_types_1.ColumnType.DOUBLE,
|
|
1401
|
-
tinyint: schema_types_1.ColumnType.BOOLEAN,
|
|
1402
|
-
date: schema_types_1.ColumnType.DATE,
|
|
1403
|
-
time: schema_types_1.ColumnType.TIME,
|
|
1404
|
-
datetime: schema_types_1.ColumnType.DATETIME,
|
|
1405
|
-
timestamp: schema_types_1.ColumnType.TIMESTAMP,
|
|
1406
|
-
json: schema_types_1.ColumnType.JSON,
|
|
1407
|
-
blob: schema_types_1.ColumnType.BLOB,
|
|
1408
|
-
binary: schema_types_1.ColumnType.BINARY,
|
|
1409
|
-
};
|
|
1410
|
-
return typeMap[mysqlType.toLowerCase()] || schema_types_1.ColumnType.TEXT;
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Ensure migration table exists
|
|
1414
|
-
*/
|
|
1415
|
-
async ensureMigrationTable(conn) {
|
|
1416
|
-
const query = `
|
|
1417
|
-
CREATE TABLE IF NOT EXISTS _ductape_migrations (
|
|
1418
|
-
tag VARCHAR(255) PRIMARY KEY,
|
|
1419
|
-
name VARCHAR(255) NOT NULL,
|
|
1420
|
-
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
1421
|
-
)
|
|
1422
|
-
`;
|
|
1423
|
-
await conn.query(query);
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Record migration execution
|
|
1427
|
-
*/
|
|
1428
|
-
async recordMigration(conn, migration, direction) {
|
|
1429
|
-
await this.ensureMigrationTable(conn);
|
|
1430
|
-
const query = `
|
|
1431
|
-
INSERT INTO _ductape_migrations (tag, name, executed_at)
|
|
1432
|
-
VALUES (?, ?, CURRENT_TIMESTAMP)
|
|
1433
|
-
ON DUPLICATE KEY UPDATE executed_at = CURRENT_TIMESTAMP
|
|
1434
|
-
`;
|
|
1435
|
-
await conn.query(query, [migration.tag, migration.name]);
|
|
1436
|
-
}
|
|
1437
|
-
/**
|
|
1438
|
-
* Remove migration from history
|
|
1439
|
-
*/
|
|
1440
|
-
async removeMigration(conn, tag) {
|
|
1441
|
-
await this.ensureMigrationTable(conn);
|
|
1442
|
-
const query = `DELETE FROM _ductape_migrations WHERE tag = ?`;
|
|
1443
|
-
await conn.query(query, [tag]);
|
|
894
|
+
const [rows] = await this.pool.query(sql, params);
|
|
895
|
+
return rows.map((row) => ({
|
|
896
|
+
indexName: row.index_name,
|
|
897
|
+
tableName: row.table_name,
|
|
898
|
+
scans: 0, // MySQL doesn't provide this easily
|
|
899
|
+
tuplesRead: 0,
|
|
900
|
+
sizeBytes: parseInt(row.size_bytes, 10) || 0,
|
|
901
|
+
sizeFormatted: this.formatBytes(parseInt(row.size_bytes, 10) || 0),
|
|
902
|
+
}));
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
throw database_error_1.DatabaseError.schemaError(`Failed to get index statistics: ${error.message}`, error);
|
|
906
|
+
}
|
|
1444
907
|
}
|
|
1445
|
-
// ====================
|
|
1446
|
-
/**
|
|
1447
|
-
* Escape identifier (table/column name)
|
|
1448
|
-
*/
|
|
908
|
+
// ==================== UTILITY METHODS ====================
|
|
1449
909
|
escapeIdentifier(identifier) {
|
|
910
|
+
// MySQL uses backticks for identifiers
|
|
1450
911
|
return `\`${identifier.replace(/`/g, '``')}\``;
|
|
1451
912
|
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Escape value for SQL
|
|
1454
|
-
*/
|
|
1455
913
|
escapeValue(value) {
|
|
1456
914
|
if (value === null || value === undefined) {
|
|
1457
915
|
return 'NULL';
|
|
1458
916
|
}
|
|
1459
|
-
if (typeof value === '
|
|
1460
|
-
return
|
|
917
|
+
if (typeof value === 'number') {
|
|
918
|
+
return String(value);
|
|
1461
919
|
}
|
|
1462
920
|
if (typeof value === 'boolean') {
|
|
1463
921
|
return value ? '1' : '0';
|
|
@@ -1465,28 +923,314 @@ class MySQLAdapter extends base_adapter_1.BaseDatabaseAdapter {
|
|
|
1465
923
|
if (value instanceof Date) {
|
|
1466
924
|
return `'${value.toISOString().slice(0, 19).replace('T', ' ')}'`;
|
|
1467
925
|
}
|
|
1468
|
-
if (Array.isArray(value)) {
|
|
1469
|
-
return `'${JSON.stringify(value)}'`;
|
|
1470
|
-
}
|
|
1471
926
|
if (typeof value === 'object') {
|
|
1472
|
-
return `'${JSON.stringify(value)}'`;
|
|
927
|
+
return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
|
|
1473
928
|
}
|
|
1474
|
-
|
|
929
|
+
// String - escape single quotes
|
|
930
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
1475
931
|
}
|
|
1476
932
|
/**
|
|
1477
|
-
*
|
|
933
|
+
* Check if value is an update operator object
|
|
1478
934
|
*/
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
935
|
+
isUpdateOperator(value) {
|
|
936
|
+
if (!value || typeof value !== 'object')
|
|
937
|
+
return false;
|
|
938
|
+
const operators = ['$INC', '$DEC', '$MUL', '$MIN', '$MAX', '$SET', '$UNSET', '$PUSH', '$PULL', '$ADDTOSET'];
|
|
939
|
+
return operators.some(op => op in value);
|
|
940
|
+
}
|
|
941
|
+
getParameterPlaceholder(index) {
|
|
942
|
+
// MySQL uses ? for all parameters
|
|
943
|
+
return '?';
|
|
944
|
+
}
|
|
945
|
+
getColumnTypeString(columnType, options) {
|
|
946
|
+
const typeMap = {
|
|
947
|
+
[enums_1.ColumnType.INTEGER]: 'INT',
|
|
948
|
+
[enums_1.ColumnType.BIGINT]: 'BIGINT',
|
|
949
|
+
[enums_1.ColumnType.SMALLINT]: 'SMALLINT',
|
|
950
|
+
[enums_1.ColumnType.FLOAT]: 'FLOAT',
|
|
951
|
+
[enums_1.ColumnType.DOUBLE]: 'DOUBLE',
|
|
952
|
+
[enums_1.ColumnType.DECIMAL]: (options === null || options === void 0 ? void 0 : options.precision)
|
|
953
|
+
? `DECIMAL(${options.precision}${options.scale ? `, ${options.scale}` : ''})`
|
|
954
|
+
: 'DECIMAL(10,2)',
|
|
955
|
+
[enums_1.ColumnType.STRING]: (options === null || options === void 0 ? void 0 : options.maxLength) ? `VARCHAR(${options.maxLength})` : 'VARCHAR(255)',
|
|
956
|
+
[enums_1.ColumnType.TEXT]: 'TEXT',
|
|
957
|
+
[enums_1.ColumnType.BOOLEAN]: 'TINYINT(1)',
|
|
958
|
+
[enums_1.ColumnType.DATE]: 'DATE',
|
|
959
|
+
[enums_1.ColumnType.DATETIME]: 'DATETIME',
|
|
960
|
+
[enums_1.ColumnType.TIMESTAMP]: 'TIMESTAMP',
|
|
961
|
+
[enums_1.ColumnType.TIME]: 'TIME',
|
|
962
|
+
[enums_1.ColumnType.JSON]: 'JSON',
|
|
963
|
+
[enums_1.ColumnType.JSONB]: 'JSON', // MySQL uses JSON for both
|
|
964
|
+
[enums_1.ColumnType.UUID]: 'CHAR(36)',
|
|
965
|
+
[enums_1.ColumnType.BINARY]: 'BLOB',
|
|
966
|
+
[enums_1.ColumnType.ENUM]: (options === null || options === void 0 ? void 0 : options.enumValues)
|
|
967
|
+
? `ENUM(${options.enumValues.map(v => `'${v}'`).join(', ')})`
|
|
968
|
+
: 'VARCHAR(255)',
|
|
969
|
+
[enums_1.ColumnType.ARRAY]: 'JSON', // MySQL doesn't have native arrays, use JSON
|
|
970
|
+
};
|
|
971
|
+
return typeMap[columnType] || columnType;
|
|
972
|
+
}
|
|
973
|
+
getSupportedFeatures() {
|
|
974
|
+
return [
|
|
975
|
+
base_adapter_1.DatabaseFeature.TRANSACTIONS,
|
|
976
|
+
base_adapter_1.DatabaseFeature.SAVEPOINTS,
|
|
977
|
+
base_adapter_1.DatabaseFeature.JSON,
|
|
978
|
+
base_adapter_1.DatabaseFeature.FULLTEXT_SEARCH,
|
|
979
|
+
base_adapter_1.DatabaseFeature.HASH_INDEX,
|
|
980
|
+
base_adapter_1.DatabaseFeature.UPSERT,
|
|
981
|
+
base_adapter_1.DatabaseFeature.FOREIGN_KEYS,
|
|
982
|
+
base_adapter_1.DatabaseFeature.CHECK_CONSTRAINTS,
|
|
983
|
+
base_adapter_1.DatabaseFeature.STORED_PROCEDURES,
|
|
984
|
+
base_adapter_1.DatabaseFeature.VIEWS,
|
|
985
|
+
base_adapter_1.DatabaseFeature.TRIGGERS,
|
|
986
|
+
base_adapter_1.DatabaseFeature.LIKE,
|
|
987
|
+
base_adapter_1.DatabaseFeature.BETWEEN,
|
|
988
|
+
base_adapter_1.DatabaseFeature.LIMIT_OFFSET,
|
|
989
|
+
base_adapter_1.DatabaseFeature.WINDOW_FUNCTIONS,
|
|
990
|
+
base_adapter_1.DatabaseFeature.CTE,
|
|
991
|
+
];
|
|
992
|
+
}
|
|
993
|
+
parseError(error) {
|
|
994
|
+
const code = error.code || error.errno;
|
|
995
|
+
let type = enums_1.DatabaseErrorType.UNKNOWN_ERROR;
|
|
996
|
+
// Map MySQL error codes
|
|
997
|
+
switch (code) {
|
|
998
|
+
case 'ER_DUP_ENTRY':
|
|
999
|
+
case 1062:
|
|
1000
|
+
type = enums_1.DatabaseErrorType.UNIQUE_VIOLATION;
|
|
1001
|
+
break;
|
|
1002
|
+
case 'ER_ROW_IS_REFERENCED':
|
|
1003
|
+
case 'ER_NO_REFERENCED_ROW':
|
|
1004
|
+
case 1451:
|
|
1005
|
+
case 1452:
|
|
1006
|
+
type = enums_1.DatabaseErrorType.FOREIGN_KEY_VIOLATION;
|
|
1007
|
+
break;
|
|
1008
|
+
case 'ER_BAD_NULL_ERROR':
|
|
1009
|
+
case 1048:
|
|
1010
|
+
type = enums_1.DatabaseErrorType.NOT_NULL_VIOLATION;
|
|
1011
|
+
break;
|
|
1012
|
+
case 'ER_ACCESS_DENIED_ERROR':
|
|
1013
|
+
case 1045:
|
|
1014
|
+
type = enums_1.DatabaseErrorType.AUTHENTICATION_ERROR;
|
|
1015
|
+
break;
|
|
1016
|
+
case 'ER_NO_SUCH_TABLE':
|
|
1017
|
+
case 1146:
|
|
1018
|
+
type = enums_1.DatabaseErrorType.SCHEMA_ERROR;
|
|
1019
|
+
break;
|
|
1020
|
+
case 'ECONNREFUSED':
|
|
1021
|
+
case 'ETIMEDOUT':
|
|
1022
|
+
type = enums_1.DatabaseErrorType.CONNECTION_ERROR;
|
|
1023
|
+
break;
|
|
1024
|
+
default:
|
|
1025
|
+
if (typeof code === 'string' && code.startsWith('ER_')) {
|
|
1026
|
+
type = enums_1.DatabaseErrorType.QUERY_ERROR;
|
|
1027
|
+
}
|
|
1485
1028
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1029
|
+
return {
|
|
1030
|
+
type,
|
|
1031
|
+
message: error.message || 'Unknown database error',
|
|
1032
|
+
code: String(code),
|
|
1033
|
+
details: {
|
|
1034
|
+
sqlState: error.sqlState,
|
|
1035
|
+
sqlMessage: error.sqlMessage,
|
|
1036
|
+
},
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
// ==================== PRIVATE HELPER METHODS ====================
|
|
1040
|
+
ensureConnected() {
|
|
1041
|
+
if (!this.connected || !this.pool) {
|
|
1042
|
+
throw new database_error_1.DatabaseError('Not connected to MySQL database', enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
1488
1043
|
}
|
|
1489
1044
|
}
|
|
1045
|
+
buildWhereClause(where) {
|
|
1046
|
+
const clauses = [];
|
|
1047
|
+
const params = [];
|
|
1048
|
+
for (const [key, value] of Object.entries(where)) {
|
|
1049
|
+
if (key === '$AND') {
|
|
1050
|
+
const andResult = this.buildWhereClause(value);
|
|
1051
|
+
clauses.push(`(${andResult.whereClause})`);
|
|
1052
|
+
params.push(...andResult.whereParams);
|
|
1053
|
+
}
|
|
1054
|
+
else if (key === '$OR') {
|
|
1055
|
+
const orClauses = [];
|
|
1056
|
+
for (const [orKey, orValue] of Object.entries(value)) {
|
|
1057
|
+
const orResult = this.buildWhereClause({ [orKey]: orValue });
|
|
1058
|
+
orClauses.push(orResult.whereClause);
|
|
1059
|
+
params.push(...orResult.whereParams);
|
|
1060
|
+
}
|
|
1061
|
+
clauses.push(`(${orClauses.join(' OR ')})`);
|
|
1062
|
+
}
|
|
1063
|
+
else if (value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
|
|
1064
|
+
// Handle operators
|
|
1065
|
+
for (const [op, opValue] of Object.entries(value)) {
|
|
1066
|
+
switch (op) {
|
|
1067
|
+
case '$EQ':
|
|
1068
|
+
clauses.push(`${this.escapeIdentifier(key)} = ?`);
|
|
1069
|
+
params.push(opValue);
|
|
1070
|
+
break;
|
|
1071
|
+
case '$NE':
|
|
1072
|
+
case '$NOT':
|
|
1073
|
+
clauses.push(`${this.escapeIdentifier(key)} != ?`);
|
|
1074
|
+
params.push(opValue);
|
|
1075
|
+
break;
|
|
1076
|
+
case '$GT':
|
|
1077
|
+
clauses.push(`${this.escapeIdentifier(key)} > ?`);
|
|
1078
|
+
params.push(opValue);
|
|
1079
|
+
break;
|
|
1080
|
+
case '$GTE':
|
|
1081
|
+
clauses.push(`${this.escapeIdentifier(key)} >= ?`);
|
|
1082
|
+
params.push(opValue);
|
|
1083
|
+
break;
|
|
1084
|
+
case '$LT':
|
|
1085
|
+
clauses.push(`${this.escapeIdentifier(key)} < ?`);
|
|
1086
|
+
params.push(opValue);
|
|
1087
|
+
break;
|
|
1088
|
+
case '$LTE':
|
|
1089
|
+
clauses.push(`${this.escapeIdentifier(key)} <= ?`);
|
|
1090
|
+
params.push(opValue);
|
|
1091
|
+
break;
|
|
1092
|
+
case '$IN':
|
|
1093
|
+
clauses.push(`${this.escapeIdentifier(key)} IN (?)`);
|
|
1094
|
+
params.push(opValue);
|
|
1095
|
+
break;
|
|
1096
|
+
case '$NOT_IN':
|
|
1097
|
+
clauses.push(`${this.escapeIdentifier(key)} NOT IN (?)`);
|
|
1098
|
+
params.push(opValue);
|
|
1099
|
+
break;
|
|
1100
|
+
case '$LIKE':
|
|
1101
|
+
clauses.push(`${this.escapeIdentifier(key)} LIKE ?`);
|
|
1102
|
+
params.push(opValue);
|
|
1103
|
+
break;
|
|
1104
|
+
case '$ILIKE':
|
|
1105
|
+
// MySQL uses LOWER() for case-insensitive comparison
|
|
1106
|
+
clauses.push(`LOWER(${this.escapeIdentifier(key)}) LIKE LOWER(?)`);
|
|
1107
|
+
params.push(opValue);
|
|
1108
|
+
break;
|
|
1109
|
+
case '$IS_NULL':
|
|
1110
|
+
clauses.push(`${this.escapeIdentifier(key)} IS ${opValue ? 'NULL' : 'NOT NULL'}`);
|
|
1111
|
+
break;
|
|
1112
|
+
case '$IS_NOT_NULL':
|
|
1113
|
+
clauses.push(`${this.escapeIdentifier(key)} IS ${opValue ? 'NOT NULL' : 'NULL'}`);
|
|
1114
|
+
break;
|
|
1115
|
+
case '$BETWEEN':
|
|
1116
|
+
const [min, max] = opValue;
|
|
1117
|
+
clauses.push(`${this.escapeIdentifier(key)} BETWEEN ? AND ?`);
|
|
1118
|
+
params.push(min, max);
|
|
1119
|
+
break;
|
|
1120
|
+
case '$CONTAINS':
|
|
1121
|
+
// MySQL uses JSON_CONTAINS for JSON columns or FIND_IN_SET for comma-separated values
|
|
1122
|
+
clauses.push(`JSON_CONTAINS(${this.escapeIdentifier(key)}, ?)`);
|
|
1123
|
+
params.push(JSON.stringify(opValue));
|
|
1124
|
+
break;
|
|
1125
|
+
case '$OVERLAPS':
|
|
1126
|
+
// MySQL 8.0+ supports JSON_OVERLAPS
|
|
1127
|
+
clauses.push(`JSON_OVERLAPS(${this.escapeIdentifier(key)}, ?)`);
|
|
1128
|
+
params.push(JSON.stringify(opValue));
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
// Simple equality
|
|
1135
|
+
clauses.push(`${this.escapeIdentifier(key)} = ?`);
|
|
1136
|
+
params.push(value);
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return {
|
|
1140
|
+
whereClause: clauses.join(' AND '),
|
|
1141
|
+
whereParams: params,
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
buildCountQuery(query) {
|
|
1145
|
+
// Build a COUNT query from the original query
|
|
1146
|
+
const fromIndex = query.sql.toUpperCase().indexOf('FROM');
|
|
1147
|
+
const orderByIndex = query.sql.toUpperCase().indexOf('ORDER BY');
|
|
1148
|
+
const limitIndex = query.sql.toUpperCase().indexOf('LIMIT');
|
|
1149
|
+
let endIndex = query.sql.length;
|
|
1150
|
+
if (orderByIndex > 0)
|
|
1151
|
+
endIndex = Math.min(endIndex, orderByIndex);
|
|
1152
|
+
if (limitIndex > 0)
|
|
1153
|
+
endIndex = Math.min(endIndex, limitIndex);
|
|
1154
|
+
return `SELECT COUNT(*) as count ${query.sql.substring(fromIndex, endIndex)}`;
|
|
1155
|
+
}
|
|
1156
|
+
buildColumnDefinition(column) {
|
|
1157
|
+
let def = `${this.escapeIdentifier(column.name)} ${this.getColumnTypeString(column.type, column)}`;
|
|
1158
|
+
if (column.autoIncrement) {
|
|
1159
|
+
def += ' AUTO_INCREMENT';
|
|
1160
|
+
}
|
|
1161
|
+
if (column.nullable === false) {
|
|
1162
|
+
def += ' NOT NULL';
|
|
1163
|
+
}
|
|
1164
|
+
if (column.unique) {
|
|
1165
|
+
def += ' UNIQUE';
|
|
1166
|
+
}
|
|
1167
|
+
if (column.primaryKey) {
|
|
1168
|
+
def += ' PRIMARY KEY';
|
|
1169
|
+
}
|
|
1170
|
+
if (column.defaultValue !== undefined) {
|
|
1171
|
+
def += ` DEFAULT ${this.escapeValue(column.defaultValue)}`;
|
|
1172
|
+
}
|
|
1173
|
+
if (column.references) {
|
|
1174
|
+
def += ` REFERENCES ${this.escapeIdentifier(column.references.table)}(${this.escapeIdentifier(column.references.column)})`;
|
|
1175
|
+
if (column.references.onDelete) {
|
|
1176
|
+
def += ` ON DELETE ${column.references.onDelete}`;
|
|
1177
|
+
}
|
|
1178
|
+
if (column.references.onUpdate) {
|
|
1179
|
+
def += ` ON UPDATE ${column.references.onUpdate}`;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (column.comment) {
|
|
1183
|
+
def += ` COMMENT ${this.escapeValue(column.comment)}`;
|
|
1184
|
+
}
|
|
1185
|
+
return def;
|
|
1186
|
+
}
|
|
1187
|
+
buildConstraintDefinition(constraint) {
|
|
1188
|
+
let def = `CONSTRAINT ${this.escapeIdentifier(constraint.name)}`;
|
|
1189
|
+
switch (constraint.type) {
|
|
1190
|
+
case 'PRIMARY_KEY':
|
|
1191
|
+
def += ` PRIMARY KEY (${constraint.columns.map((c) => this.escapeIdentifier(c)).join(', ')})`;
|
|
1192
|
+
break;
|
|
1193
|
+
case 'UNIQUE':
|
|
1194
|
+
def += ` UNIQUE (${constraint.columns.map((c) => this.escapeIdentifier(c)).join(', ')})`;
|
|
1195
|
+
break;
|
|
1196
|
+
case 'FOREIGN_KEY':
|
|
1197
|
+
def += ` FOREIGN KEY (${constraint.columns.map((c) => this.escapeIdentifier(c)).join(', ')})`;
|
|
1198
|
+
def += ` REFERENCES ${this.escapeIdentifier(constraint.references.table)}(${this.escapeIdentifier(constraint.references.column)})`;
|
|
1199
|
+
if (constraint.references.onDelete) {
|
|
1200
|
+
def += ` ON DELETE ${constraint.references.onDelete}`;
|
|
1201
|
+
}
|
|
1202
|
+
if (constraint.references.onUpdate) {
|
|
1203
|
+
def += ` ON UPDATE ${constraint.references.onUpdate}`;
|
|
1204
|
+
}
|
|
1205
|
+
break;
|
|
1206
|
+
case 'CHECK':
|
|
1207
|
+
def += ` CHECK (${constraint.expression})`;
|
|
1208
|
+
break;
|
|
1209
|
+
}
|
|
1210
|
+
return def;
|
|
1211
|
+
}
|
|
1212
|
+
mapIsolationLevel(level) {
|
|
1213
|
+
switch (level) {
|
|
1214
|
+
case enums_1.IsolationLevel.READ_UNCOMMITTED:
|
|
1215
|
+
return 'READ UNCOMMITTED';
|
|
1216
|
+
case enums_1.IsolationLevel.READ_COMMITTED:
|
|
1217
|
+
return 'READ COMMITTED';
|
|
1218
|
+
case enums_1.IsolationLevel.REPEATABLE_READ:
|
|
1219
|
+
return 'REPEATABLE READ';
|
|
1220
|
+
case enums_1.IsolationLevel.SERIALIZABLE:
|
|
1221
|
+
return 'SERIALIZABLE';
|
|
1222
|
+
default:
|
|
1223
|
+
return 'REPEATABLE READ'; // MySQL default
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
formatBytes(bytes) {
|
|
1227
|
+
if (bytes === 0)
|
|
1228
|
+
return '0 B';
|
|
1229
|
+
const k = 1024;
|
|
1230
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
1231
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
1232
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
1233
|
+
}
|
|
1490
1234
|
}
|
|
1491
1235
|
exports.MySQLAdapter = MySQLAdapter;
|
|
1492
1236
|
//# sourceMappingURL=mysql.adapter.js.map
|