@relq/orm 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +33 -224
- package/dist/cjs/addon/cursor.cjs +4 -3
- package/dist/cjs/addon/mysql2.cjs +21144 -0
- package/dist/cjs/addon/pg.cjs +4 -3
- package/dist/cjs/cache/query-cache.cjs +1 -4
- package/dist/cjs/core/cte/cte-accessor.cjs +80 -0
- package/dist/cjs/core/cte/cte-types.cjs +24 -0
- package/dist/cjs/core/cte/native-cte-builder.cjs +254 -0
- package/dist/cjs/core/helpers/index.cjs +14 -14
- package/dist/cjs/core/relq-base.cjs +4 -88
- package/dist/cjs/core/relq-client.cjs +52 -25
- package/dist/cjs/core/shared/column-mapping.cjs +1 -1
- package/dist/cjs/core/shared/table-accessor.cjs +1 -1
- package/dist/cjs/core/shared/where.cjs +15 -0
- package/dist/cjs/index.cjs +40 -5
- package/dist/cjs/mysql/clients/index.cjs +17 -0
- package/dist/cjs/mysql/clients/mariadb-client/capabilities.cjs +31 -0
- package/dist/cjs/mysql/clients/mariadb-client/index.cjs +7 -0
- package/dist/cjs/mysql/clients/mariadb-client/relq-mariadb.cjs +14 -0
- package/dist/cjs/mysql/clients/mysql-client/capabilities.cjs +31 -0
- package/dist/cjs/mysql/clients/mysql-client/index.cjs +7 -0
- package/dist/cjs/mysql/clients/mysql-client/relq-mysql.cjs +14 -0
- package/dist/cjs/mysql/clients/planetscale-client/capabilities.cjs +31 -0
- package/dist/cjs/mysql/clients/planetscale-client/index.cjs +7 -0
- package/dist/cjs/mysql/clients/planetscale-client/relq-planetscale.cjs +32 -0
- package/dist/cjs/mysql/clients/shared/index.cjs +32 -0
- package/dist/cjs/mysql/clients/shared/mysql-base.cjs +362 -0
- package/dist/cjs/mysql/clients/shared/mysql-dialect.cjs +141 -0
- package/dist/cjs/mysql/clients/shared/mysql-error-parser.cjs +195 -0
- package/dist/cjs/mysql/clients/shared/mysql-format.cjs +95 -0
- package/dist/cjs/mysql/clients/shared/mysql-type-coercion.cjs +14 -0
- package/dist/cjs/mysql/condition/condition-collector.cjs +377 -0
- package/dist/cjs/mysql/condition/fulltext-condition-builder.cjs +63 -0
- package/dist/cjs/mysql/condition/index.cjs +16 -0
- package/dist/cjs/mysql/condition/json-condition-builder.cjs +144 -0
- package/dist/cjs/mysql/condition/json-path-proxy.cjs +520 -0
- package/dist/cjs/mysql/count/count-builder.cjs +109 -0
- package/dist/cjs/mysql/count/index.cjs +5 -0
- package/dist/cjs/mysql/delete/delete-builder.cjs +105 -0
- package/dist/cjs/mysql/delete/index.cjs +5 -0
- package/dist/cjs/mysql/explain/explain-builder.cjs +43 -0
- package/dist/cjs/mysql/explain/index.cjs +5 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedAggregateBuilder.cjs +132 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedCountBuilder.cjs +83 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedDeleteBuilder.cjs +91 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedInsertBuilder.cjs +75 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedInsertFromSelectBuilder.cjs +57 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedQueryBuilder.cjs +141 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedRawQueryBuilder.cjs +60 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedSelectBuilder.cjs +398 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedTransactionBuilder.cjs +128 -0
- package/dist/cjs/mysql/helpers/MysqlConnectedUpdateBuilder.cjs +92 -0
- package/dist/cjs/mysql/helpers/MysqlPaginateBuilder.cjs +186 -0
- package/dist/cjs/mysql/helpers/MysqlReturningExecutor.cjs +69 -0
- package/dist/cjs/mysql/helpers/index.cjs +45 -0
- package/dist/cjs/mysql/helpers/query-convenience.cjs +210 -0
- package/dist/cjs/mysql/helpers/select-joins.cjs +465 -0
- package/dist/cjs/mysql/helpers/select-pagination.cjs +190 -0
- package/dist/cjs/mysql/index.cjs +154 -0
- package/dist/cjs/mysql/insert/duplicate-key-builder.cjs +185 -0
- package/dist/cjs/mysql/insert/index.cjs +13 -0
- package/dist/cjs/mysql/insert/insert-builder.cjs +169 -0
- package/dist/cjs/mysql/insert/insert-from-select-builder.cjs +74 -0
- package/dist/cjs/mysql/raw/index.cjs +8 -0
- package/dist/cjs/mysql/raw/raw-query-builder.cjs +27 -0
- package/dist/cjs/mysql/raw/sql-template.cjs +65 -0
- package/dist/cjs/mysql/select/aggregate-builder.cjs +211 -0
- package/dist/cjs/mysql/select/index.cjs +32 -0
- package/dist/cjs/mysql/select/join-builder.cjs +206 -0
- package/dist/cjs/mysql/select/join-condition-builder.cjs +205 -0
- package/dist/cjs/mysql/select/join-internals.cjs +5 -0
- package/dist/cjs/mysql/select/scalar-query-builder.cjs +164 -0
- package/dist/cjs/mysql/select/scalar-select-builder.cjs +78 -0
- package/dist/cjs/mysql/select/select-builder.cjs +414 -0
- package/dist/cjs/mysql/select/sql-expression.cjs +56 -0
- package/dist/cjs/mysql/select/table-proxy.cjs +99 -0
- package/dist/cjs/mysql/shared/mysql-table-accessor.cjs +22 -0
- package/dist/cjs/mysql/transaction/index.cjs +6 -0
- package/dist/cjs/mysql/transaction/transaction-builder.cjs +64 -0
- package/dist/cjs/mysql/update/column-expression-builder.cjs +49 -0
- package/dist/cjs/mysql/update/index.cjs +7 -0
- package/dist/cjs/mysql/update/mysql-json-update-builder.cjs +200 -0
- package/dist/cjs/mysql/update/update-builder.cjs +167 -0
- package/dist/cjs/mysql/utils/addon/mysql/mysql2.cjs +23 -0
- package/dist/cjs/mysql/utils/fk-resolver.cjs +187 -0
- package/dist/cjs/mysql/utils/index.cjs +16 -0
- package/dist/cjs/mysql/utils/type-coercion.cjs +158 -0
- package/dist/cjs/mysql/window/index.cjs +5 -0
- package/dist/cjs/mysql/window/window-builder.cjs +80 -0
- package/dist/cjs/pg/clients/alloydb-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/alloydb-client/index.cjs +7 -0
- package/dist/cjs/pg/clients/alloydb-client/relq-alloydb.cjs +43 -0
- package/dist/cjs/pg/clients/aurora-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/aurora-client/index.cjs +7 -0
- package/dist/cjs/pg/clients/aurora-client/relq-aurora.cjs +43 -0
- package/dist/cjs/pg/clients/citus-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/citus-client/index.cjs +7 -0
- package/dist/cjs/pg/clients/citus-client/relq-citus.cjs +43 -0
- package/dist/cjs/pg/clients/neon-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/neon-client/index.cjs +7 -0
- package/dist/cjs/pg/clients/neon-client/relq-neon.cjs +43 -0
- package/dist/cjs/pg/clients/pg-client/relq-postgres.cjs +56 -0
- package/dist/cjs/{core/pg-family → pg/clients}/shared/pg-base.cjs +64 -7
- package/dist/cjs/{core/pg-family → pg/clients}/shared/pg-type-coercion.cjs +1 -1
- package/dist/cjs/pg/clients/supabase-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/supabase-client/index.cjs +7 -0
- package/dist/cjs/{core/pg-family/pg-client/relq-postgres.cjs → pg/clients/supabase-client/relq-supabase.cjs} +9 -9
- package/dist/cjs/pg/clients/timescale-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/timescale-client/index.cjs +7 -0
- package/dist/cjs/pg/clients/timescale-client/relq-timescale.cjs +43 -0
- package/dist/cjs/pg/clients/yugabytedb-client/capabilities.cjs +31 -0
- package/dist/cjs/pg/clients/yugabytedb-client/index.cjs +7 -0
- package/dist/cjs/pg/clients/yugabytedb-client/relq-yugabytedb.cjs +16 -0
- package/dist/cjs/{condition → pg/condition}/array-condition-builder.cjs +1 -1
- package/dist/cjs/pg/condition/array-path-proxy.cjs +379 -0
- package/dist/cjs/{condition → pg/condition}/condition-collector.cjs +18 -9
- package/dist/cjs/{condition → pg/condition}/fulltext-condition-builder.cjs +1 -1
- package/dist/cjs/{condition → pg/condition}/geometric-condition-builder.cjs +1 -1
- package/dist/cjs/pg/condition/json-path-proxy.cjs +480 -0
- package/dist/cjs/{condition → pg/condition}/jsonb-condition-builder.cjs +1 -1
- package/dist/cjs/{condition → pg/condition}/network-condition-builder.cjs +1 -1
- package/dist/cjs/{condition → pg/condition}/postgis-condition-builder.cjs +1 -1
- package/dist/cjs/{condition → pg/condition}/range-condition-builder.cjs +1 -1
- package/dist/cjs/{count → pg/count}/count-builder.cjs +10 -5
- package/dist/cjs/{delete → pg/delete}/delete-builder.cjs +10 -5
- package/dist/cjs/{core → pg}/helpers/ConnectedAggregateBuilder.cjs +16 -3
- package/dist/cjs/{core → pg}/helpers/ConnectedCountBuilder.cjs +16 -3
- package/dist/cjs/{core → pg}/helpers/ConnectedDeleteBuilder.cjs +27 -7
- package/dist/cjs/{core → pg}/helpers/ConnectedInsertBuilder.cjs +16 -8
- package/dist/cjs/{core → pg}/helpers/ConnectedInsertFromSelectBuilder.cjs +9 -5
- package/dist/cjs/{core → pg}/helpers/ConnectedQueryBuilder.cjs +14 -19
- package/dist/cjs/pg/helpers/ConnectedRawQueryBuilder.cjs +67 -0
- package/dist/cjs/{core → pg}/helpers/ConnectedSelectBuilder.cjs +121 -25
- package/dist/cjs/{core → pg}/helpers/ConnectedTransactionBuilder.cjs +34 -4
- package/dist/cjs/{core → pg}/helpers/ConnectedUpdateBuilder.cjs +27 -7
- package/dist/cjs/{core → pg}/helpers/PaginateBuilder.cjs +3 -3
- package/dist/cjs/{core → pg}/helpers/ReturningExecutor.cjs +3 -3
- package/dist/cjs/{core → pg}/helpers/query-convenience.cjs +11 -12
- package/dist/cjs/{core → pg}/helpers/select-joins.cjs +17 -14
- package/dist/cjs/{core → pg}/helpers/select-pagination.cjs +1 -1
- package/dist/cjs/{insert → pg/insert}/conflict-builder.cjs +2 -2
- package/dist/cjs/{insert → pg/insert}/insert-builder.cjs +8 -5
- package/dist/cjs/{insert → pg/insert}/insert-from-select-builder.cjs +1 -1
- package/dist/cjs/{pubsub → pg/pubsub}/listen-notify-builder.cjs +1 -1
- package/dist/cjs/{pubsub → pg/pubsub}/listener-connection.cjs +2 -2
- package/dist/cjs/{raw → pg/raw}/raw-query-builder.cjs +2 -2
- package/dist/cjs/{raw → pg/raw}/sql-template.cjs +1 -6
- package/dist/cjs/{select → pg/select}/aggregate-builder.cjs +10 -5
- package/dist/cjs/{select → pg/select}/join-builder.cjs +2 -2
- package/dist/cjs/{select → pg/select}/join-condition-builder.cjs +11 -1
- package/dist/cjs/{select → pg/select}/join-many-condition-builder.cjs +3 -4
- package/dist/cjs/{select → pg/select}/scalar-query-builder.cjs +31 -1
- package/dist/cjs/{select → pg/select}/scalar-select-builder.cjs +1 -1
- package/dist/cjs/{select → pg/select}/select-builder.cjs +40 -7
- package/dist/cjs/pg/select/sql-expression.cjs +56 -0
- package/dist/cjs/{transaction → pg/transaction}/transaction-builder.cjs +1 -1
- package/dist/cjs/{update → pg/update}/array-update-builder.cjs +2 -5
- package/dist/cjs/pg/update/column-expression-builder.cjs +49 -0
- package/dist/cjs/{update → pg/update}/jsonb-update-builder.cjs +1 -1
- package/dist/cjs/{update → pg/update}/update-builder.cjs +14 -7
- package/dist/cjs/{utils → pg/utils}/addon/pg/cursor.cjs +1 -1
- package/dist/cjs/{utils → pg/utils}/addon/pg/pg.cjs +2 -2
- package/dist/cjs/{utils → pg/utils}/fk-resolver.cjs +47 -30
- package/dist/cjs/{window → pg/window}/window-builder.cjs +1 -1
- package/dist/cjs/shared/errors/relq-errors.cjs +496 -35
- package/dist/cjs/shared/types/config-types.cjs +11 -4
- package/dist/cjs/utils/env-resolver.cjs +76 -13
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/esm/addon/cursor.js +4 -3
- package/dist/esm/addon/mysql2.js +21132 -0
- package/dist/esm/addon/pg.js +4 -3
- package/dist/esm/cache/query-cache.js +1 -4
- package/dist/esm/core/cte/cte-accessor.js +75 -0
- package/dist/esm/core/cte/cte-types.js +20 -0
- package/dist/esm/core/cte/native-cte-builder.js +250 -0
- package/dist/esm/core/helpers/index.js +12 -12
- package/dist/esm/core/relq-base.js +5 -56
- package/dist/esm/core/relq-client.js +44 -24
- package/dist/esm/core/shared/column-mapping.js +1 -1
- package/dist/esm/core/shared/table-accessor.js +1 -1
- package/dist/esm/core/shared/where.js +12 -0
- package/dist/esm/index.js +17 -5
- package/dist/esm/mysql/clients/index.js +5 -0
- package/dist/esm/mysql/clients/mariadb-client/capabilities.js +28 -0
- package/dist/esm/mysql/clients/mariadb-client/index.js +2 -0
- package/dist/esm/mysql/clients/mariadb-client/relq-mariadb.js +10 -0
- package/dist/esm/mysql/clients/mysql-client/capabilities.js +28 -0
- package/dist/esm/mysql/clients/mysql-client/index.js +2 -0
- package/dist/esm/mysql/clients/mysql-client/relq-mysql.js +10 -0
- package/dist/esm/mysql/clients/planetscale-client/capabilities.js +28 -0
- package/dist/esm/mysql/clients/planetscale-client/index.js +2 -0
- package/dist/esm/mysql/clients/planetscale-client/relq-planetscale.js +28 -0
- package/dist/esm/mysql/clients/shared/index.js +7 -0
- package/dist/esm/mysql/clients/shared/mysql-base.js +321 -0
- package/dist/esm/mysql/clients/shared/mysql-dialect.js +136 -0
- package/dist/esm/mysql/clients/shared/mysql-error-parser.js +188 -0
- package/dist/esm/mysql/clients/shared/mysql-format.js +92 -0
- package/dist/esm/mysql/clients/shared/mysql-type-coercion.js +6 -0
- package/dist/esm/mysql/condition/condition-collector.js +368 -0
- package/dist/esm/mysql/condition/fulltext-condition-builder.js +55 -0
- package/dist/esm/mysql/condition/index.js +4 -0
- package/dist/esm/mysql/condition/json-condition-builder.js +136 -0
- package/dist/esm/mysql/condition/json-path-proxy.js +513 -0
- package/dist/esm/mysql/count/count-builder.js +102 -0
- package/dist/esm/mysql/count/index.js +1 -0
- package/dist/esm/mysql/delete/delete-builder.js +98 -0
- package/dist/esm/mysql/delete/index.js +1 -0
- package/dist/esm/mysql/explain/explain-builder.js +39 -0
- package/dist/esm/mysql/explain/index.js +1 -0
- package/dist/esm/mysql/helpers/MysqlConnectedAggregateBuilder.js +128 -0
- package/dist/esm/{core/helpers/ConnectedCountBuilder.js → mysql/helpers/MysqlConnectedCountBuilder.js} +15 -5
- package/dist/esm/mysql/helpers/MysqlConnectedDeleteBuilder.js +87 -0
- package/dist/esm/mysql/helpers/MysqlConnectedInsertBuilder.js +71 -0
- package/dist/esm/mysql/helpers/MysqlConnectedInsertFromSelectBuilder.js +53 -0
- package/dist/esm/mysql/helpers/MysqlConnectedQueryBuilder.js +137 -0
- package/dist/esm/mysql/helpers/MysqlConnectedRawQueryBuilder.js +56 -0
- package/dist/esm/mysql/helpers/MysqlConnectedSelectBuilder.js +391 -0
- package/dist/esm/mysql/helpers/MysqlConnectedTransactionBuilder.js +123 -0
- package/dist/esm/mysql/helpers/MysqlConnectedUpdateBuilder.js +88 -0
- package/dist/esm/mysql/helpers/MysqlPaginateBuilder.js +182 -0
- package/dist/esm/mysql/helpers/MysqlReturningExecutor.js +65 -0
- package/dist/esm/mysql/helpers/index.js +15 -0
- package/dist/esm/mysql/helpers/query-convenience.js +199 -0
- package/dist/esm/mysql/helpers/select-joins.js +455 -0
- package/dist/esm/mysql/helpers/select-pagination.js +186 -0
- package/dist/esm/mysql/index.js +47 -0
- package/dist/esm/mysql/insert/duplicate-key-builder.js +174 -0
- package/dist/esm/mysql/insert/index.js +3 -0
- package/dist/esm/mysql/insert/insert-builder.js +162 -0
- package/dist/esm/mysql/insert/insert-from-select-builder.js +67 -0
- package/dist/esm/mysql/raw/index.js +2 -0
- package/dist/esm/mysql/raw/raw-query-builder.js +20 -0
- package/dist/esm/mysql/raw/sql-template.js +58 -0
- package/dist/esm/mysql/select/aggregate-builder.js +204 -0
- package/dist/esm/mysql/select/index.js +9 -0
- package/dist/esm/mysql/select/join-builder.js +198 -0
- package/dist/esm/mysql/select/join-condition-builder.js +197 -0
- package/dist/esm/mysql/select/join-internals.js +2 -0
- package/dist/esm/mysql/select/scalar-query-builder.js +156 -0
- package/dist/esm/mysql/select/scalar-select-builder.js +70 -0
- package/dist/esm/mysql/select/select-builder.js +407 -0
- package/dist/esm/mysql/select/sql-expression.js +51 -0
- package/dist/esm/mysql/select/table-proxy.js +91 -0
- package/dist/esm/mysql/shared/mysql-table-accessor.js +19 -0
- package/dist/esm/mysql/transaction/index.js +1 -0
- package/dist/esm/mysql/transaction/transaction-builder.js +56 -0
- package/dist/esm/mysql/update/column-expression-builder.js +42 -0
- package/dist/esm/mysql/update/index.js +2 -0
- package/dist/esm/mysql/update/mysql-json-update-builder.js +193 -0
- package/dist/esm/mysql/update/update-builder.js +160 -0
- package/dist/esm/mysql/utils/addon/mysql/mysql2.js +2 -0
- package/dist/esm/mysql/utils/fk-resolver.js +179 -0
- package/dist/esm/mysql/utils/index.js +2 -0
- package/dist/esm/mysql/utils/type-coercion.js +150 -0
- package/dist/esm/mysql/window/index.js +1 -0
- package/dist/esm/mysql/window/window-builder.js +73 -0
- package/dist/esm/pg/clients/alloydb-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/alloydb-client/index.js +2 -0
- package/dist/esm/{core/pg-family/pg-client/relq-postgres.js → pg/clients/alloydb-client/relq-alloydb.js} +8 -8
- package/dist/esm/pg/clients/aurora-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/aurora-client/index.js +2 -0
- package/dist/esm/pg/clients/aurora-client/relq-aurora.js +39 -0
- package/dist/esm/pg/clients/citus-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/citus-client/index.js +2 -0
- package/dist/esm/pg/clients/citus-client/relq-citus.js +39 -0
- package/dist/esm/pg/clients/neon-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/neon-client/index.js +2 -0
- package/dist/esm/pg/clients/neon-client/relq-neon.js +39 -0
- package/dist/esm/pg/clients/pg-client/relq-postgres.js +52 -0
- package/dist/esm/{core/pg-family → pg/clients}/shared/pg-base.js +64 -7
- package/dist/esm/{core/pg-family → pg/clients}/shared/pg-type-coercion.js +1 -1
- package/dist/esm/pg/clients/supabase-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/supabase-client/index.js +2 -0
- package/dist/esm/pg/clients/supabase-client/relq-supabase.js +39 -0
- package/dist/esm/pg/clients/timescale-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/timescale-client/index.js +2 -0
- package/dist/esm/pg/clients/timescale-client/relq-timescale.js +39 -0
- package/dist/esm/pg/clients/yugabytedb-client/capabilities.js +28 -0
- package/dist/esm/pg/clients/yugabytedb-client/index.js +2 -0
- package/dist/esm/pg/clients/yugabytedb-client/relq-yugabytedb.js +12 -0
- package/dist/esm/{condition → pg/condition}/array-condition-builder.js +1 -1
- package/dist/esm/pg/condition/array-path-proxy.js +372 -0
- package/dist/esm/{condition → pg/condition}/condition-collector.js +20 -11
- package/dist/esm/{condition → pg/condition}/fulltext-condition-builder.js +1 -1
- package/dist/esm/{condition → pg/condition}/geometric-condition-builder.js +1 -1
- package/dist/esm/pg/condition/json-path-proxy.js +473 -0
- package/dist/esm/{condition → pg/condition}/jsonb-condition-builder.js +1 -1
- package/dist/esm/{condition → pg/condition}/network-condition-builder.js +1 -1
- package/dist/esm/{condition → pg/condition}/postgis-condition-builder.js +1 -1
- package/dist/esm/{condition → pg/condition}/range-condition-builder.js +1 -1
- package/dist/esm/{count → pg/count}/count-builder.js +10 -5
- package/dist/esm/{delete → pg/delete}/delete-builder.js +10 -5
- package/dist/esm/{core → pg}/helpers/ConnectedAggregateBuilder.js +16 -3
- package/dist/esm/pg/helpers/ConnectedCountBuilder.js +82 -0
- package/dist/esm/{core → pg}/helpers/ConnectedDeleteBuilder.js +27 -7
- package/dist/esm/{core → pg}/helpers/ConnectedInsertBuilder.js +16 -8
- package/dist/esm/{core → pg}/helpers/ConnectedInsertFromSelectBuilder.js +9 -5
- package/dist/esm/{core → pg}/helpers/ConnectedQueryBuilder.js +15 -20
- package/dist/esm/pg/helpers/ConnectedRawQueryBuilder.js +63 -0
- package/dist/esm/{core → pg}/helpers/ConnectedSelectBuilder.js +118 -25
- package/dist/esm/{core → pg}/helpers/ConnectedTransactionBuilder.js +34 -4
- package/dist/esm/{core → pg}/helpers/ConnectedUpdateBuilder.js +27 -7
- package/dist/esm/{core → pg}/helpers/PaginateBuilder.js +3 -3
- package/dist/esm/{core → pg}/helpers/ReturningExecutor.js +3 -3
- package/dist/esm/{core → pg}/helpers/query-convenience.js +11 -12
- package/dist/esm/{core → pg}/helpers/select-joins.js +18 -15
- package/dist/esm/{core → pg}/helpers/select-pagination.js +1 -1
- package/dist/esm/{insert → pg/insert}/conflict-builder.js +2 -2
- package/dist/esm/{insert → pg/insert}/insert-builder.js +8 -5
- package/dist/esm/{insert → pg/insert}/insert-from-select-builder.js +1 -1
- package/dist/esm/{pubsub → pg/pubsub}/listen-notify-builder.js +1 -1
- package/dist/esm/{pubsub → pg/pubsub}/listener-connection.js +2 -2
- package/dist/esm/{raw → pg/raw}/raw-query-builder.js +2 -2
- package/dist/esm/{raw → pg/raw}/sql-template.js +1 -6
- package/dist/esm/{select → pg/select}/aggregate-builder.js +10 -5
- package/dist/esm/{select → pg/select}/join-builder.js +2 -2
- package/dist/esm/{select → pg/select}/join-condition-builder.js +11 -1
- package/dist/esm/{select → pg/select}/join-many-condition-builder.js +3 -4
- package/dist/esm/{select → pg/select}/scalar-query-builder.js +31 -1
- package/dist/esm/{select → pg/select}/scalar-select-builder.js +1 -1
- package/dist/esm/{select → pg/select}/select-builder.js +40 -7
- package/dist/esm/pg/select/sql-expression.js +51 -0
- package/dist/esm/{transaction → pg/transaction}/transaction-builder.js +1 -1
- package/dist/esm/{update → pg/update}/array-update-builder.js +2 -5
- package/dist/esm/pg/update/column-expression-builder.js +42 -0
- package/dist/esm/{update → pg/update}/jsonb-update-builder.js +1 -1
- package/dist/esm/{update → pg/update}/update-builder.js +14 -7
- package/dist/esm/pg/utils/addon/pg/cursor.js +1 -0
- package/dist/esm/pg/utils/addon/pg/pg.js +2 -0
- package/dist/esm/{utils → pg/utils}/fk-resolver.js +47 -30
- package/dist/esm/{window → pg/window}/window-builder.js +1 -1
- package/dist/esm/shared/errors/relq-errors.js +486 -34
- package/dist/esm/shared/types/config-types.js +10 -3
- package/dist/esm/utils/env-resolver.js +74 -13
- package/dist/esm/utils/index.js +1 -1
- package/dist/index.d.ts +9629 -3974
- package/package.json +5 -3
- package/dist/cjs/core/helpers/ConnectedCTEBuilder.cjs +0 -53
- package/dist/cjs/core/helpers/ConnectedRawQueryBuilder.cjs +0 -46
- package/dist/cjs/select/sql-expression.cjs +0 -38
- package/dist/esm/core/helpers/ConnectedCTEBuilder.js +0 -49
- package/dist/esm/core/helpers/ConnectedRawQueryBuilder.js +0 -42
- package/dist/esm/select/sql-expression.js +0 -33
- package/dist/esm/utils/addon/pg/cursor.js +0 -1
- package/dist/esm/utils/addon/pg/pg.js +0 -2
- /package/dist/cjs/{core/pg-family → pg/clients}/cockroachdb-client/capabilities.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/cockroachdb-client/index.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/cockroachdb-client/relq-cockroach.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/dsql-client/capabilities.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/dsql-client/index.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/dsql-client/relq-dsql.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/index.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/nile-client/capabilities.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/nile-client/index.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/nile-client/relq-nile.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/nile-client/tenant-context.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/pg-client/capabilities.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/pg-client/index.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/shared/pg-dialect.cjs +0 -0
- /package/dist/cjs/{core/pg-family → pg/clients}/shared/pg-error-parser.cjs +0 -0
- /package/dist/cjs/{condition → pg/condition}/array-numeric-condition-builder.cjs +0 -0
- /package/dist/cjs/{condition → pg/condition}/array-specialized-condition-builder.cjs +0 -0
- /package/dist/cjs/{condition → pg/condition}/array-string-condition-builder.cjs +0 -0
- /package/dist/cjs/{condition → pg/condition}/index.cjs +0 -0
- /package/dist/cjs/{count → pg/count}/index.cjs +0 -0
- /package/dist/cjs/{delete → pg/delete}/index.cjs +0 -0
- /package/dist/cjs/{explain → pg/explain}/explain-builder.cjs +0 -0
- /package/dist/cjs/{explain → pg/explain}/index.cjs +0 -0
- /package/dist/cjs/{insert → pg/insert}/index.cjs +0 -0
- /package/dist/cjs/{pubsub → pg/pubsub}/index.cjs +0 -0
- /package/dist/cjs/{raw → pg/raw}/index.cjs +0 -0
- /package/dist/cjs/{select → pg/select}/index.cjs +0 -0
- /package/dist/cjs/{select → pg/select}/join-internals.cjs +0 -0
- /package/dist/cjs/{select → pg/select}/table-proxy.cjs +0 -0
- /package/dist/cjs/{transaction → pg/transaction}/index.cjs +0 -0
- /package/dist/cjs/{update → pg/update}/index.cjs +0 -0
- /package/dist/cjs/{utils → pg/utils}/type-coercion.cjs +0 -0
- /package/dist/cjs/{window → pg/window}/index.cjs +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/cockroachdb-client/capabilities.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/cockroachdb-client/index.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/cockroachdb-client/relq-cockroach.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/dsql-client/capabilities.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/dsql-client/index.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/dsql-client/relq-dsql.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/index.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/nile-client/capabilities.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/nile-client/index.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/nile-client/relq-nile.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/nile-client/tenant-context.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/pg-client/capabilities.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/pg-client/index.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/shared/pg-dialect.js +0 -0
- /package/dist/esm/{core/pg-family → pg/clients}/shared/pg-error-parser.js +0 -0
- /package/dist/esm/{condition → pg/condition}/array-numeric-condition-builder.js +0 -0
- /package/dist/esm/{condition → pg/condition}/array-specialized-condition-builder.js +0 -0
- /package/dist/esm/{condition → pg/condition}/array-string-condition-builder.js +0 -0
- /package/dist/esm/{condition → pg/condition}/index.js +0 -0
- /package/dist/esm/{count → pg/count}/index.js +0 -0
- /package/dist/esm/{delete → pg/delete}/index.js +0 -0
- /package/dist/esm/{explain → pg/explain}/explain-builder.js +0 -0
- /package/dist/esm/{explain → pg/explain}/index.js +0 -0
- /package/dist/esm/{insert → pg/insert}/index.js +0 -0
- /package/dist/esm/{pubsub → pg/pubsub}/index.js +0 -0
- /package/dist/esm/{raw → pg/raw}/index.js +0 -0
- /package/dist/esm/{select → pg/select}/index.js +0 -0
- /package/dist/esm/{select → pg/select}/join-internals.js +0 -0
- /package/dist/esm/{select → pg/select}/table-proxy.js +0 -0
- /package/dist/esm/{transaction → pg/transaction}/index.js +0 -0
- /package/dist/esm/{update → pg/update}/index.js +0 -0
- /package/dist/esm/{utils → pg/utils}/type-coercion.js +0 -0
- /package/dist/esm/{window → pg/window}/index.js +0 -0
|
@@ -3,9 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RelqBuilderError = exports.RelqEnvironmentError = exports.RelqPoolError = exports.RelqTimeoutError = exports.RelqConfigError = exports.RelqTransactionError = exports.RelqQueryError = exports.RelqConnectionError = exports.RelqError = void 0;
|
|
6
|
+
exports.RelqLockError = exports.RelqDataError = exports.RelqSchemaError = exports.RelqConstraintError = exports.RelqBuilderError = exports.RelqEnvironmentError = exports.RelqPoolError = exports.RelqTimeoutError = exports.RelqConfigError = exports.RelqTransactionError = exports.RelqQueryError = exports.RelqConnectionError = exports.RelqError = void 0;
|
|
7
7
|
exports.setupErrorHandler = setupErrorHandler;
|
|
8
|
+
exports.getOriginalError = getOriginalError;
|
|
8
9
|
exports.isRelqError = isRelqError;
|
|
10
|
+
exports.isRelqConstraintError = isRelqConstraintError;
|
|
11
|
+
exports.isRelqSchemaError = isRelqSchemaError;
|
|
12
|
+
exports.isRelqDataError = isRelqDataError;
|
|
13
|
+
exports.isRelqLockError = isRelqLockError;
|
|
9
14
|
exports.isRelqConnectionError = isRelqConnectionError;
|
|
10
15
|
exports.isRelqQueryError = isRelqQueryError;
|
|
11
16
|
exports.isRelqBuilderError = isRelqBuilderError;
|
|
@@ -57,34 +62,93 @@ function setupErrorHandler() {
|
|
|
57
62
|
node_process_1.default.exit();
|
|
58
63
|
});
|
|
59
64
|
}
|
|
65
|
+
const ORIGINAL_ERROR = Symbol('relq-original-error');
|
|
66
|
+
let _errorHandlerInstalled = false;
|
|
67
|
+
function _autoInstallErrorHandler() {
|
|
68
|
+
if (_errorHandlerInstalled)
|
|
69
|
+
return;
|
|
70
|
+
_errorHandlerInstalled = true;
|
|
71
|
+
if (typeof node_process_1.default === 'undefined' || !node_process_1.default.on)
|
|
72
|
+
return;
|
|
73
|
+
const formatRelqError = (error) => {
|
|
74
|
+
const lines = [
|
|
75
|
+
'',
|
|
76
|
+
` \x1b[1m\x1b[31m${error.name}\x1b[0m: ${error.message}`,
|
|
77
|
+
];
|
|
78
|
+
const props = error._getInspectProps?.() || {};
|
|
79
|
+
for (const [key, value] of Object.entries(props)) {
|
|
80
|
+
if (value === undefined)
|
|
81
|
+
continue;
|
|
82
|
+
const strVal = typeof value === 'string' ? value : JSON.stringify(value);
|
|
83
|
+
lines.push(` \x1b[2m${key.padStart(16)}:\x1b[0m ${strVal}`);
|
|
84
|
+
}
|
|
85
|
+
lines.push(` \x1b[2m timestamp:\x1b[0m ${error.timestamp.toISOString()}`);
|
|
86
|
+
lines.push('');
|
|
87
|
+
return lines.join('\n');
|
|
88
|
+
};
|
|
89
|
+
node_process_1.default.on('uncaughtException', (error) => {
|
|
90
|
+
if (error instanceof RelqError) {
|
|
91
|
+
console.error(formatRelqError(error));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.error(`${error.name || 'Error'}: ${error.message}`);
|
|
95
|
+
if (error.stack) {
|
|
96
|
+
const stackLines = error.stack.split('\n').filter((line) => line.trim().startsWith('at '));
|
|
97
|
+
console.error(stackLines.slice(0, 5).join('\n'));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
node_process_1.default.exit(1);
|
|
101
|
+
});
|
|
102
|
+
node_process_1.default.on('unhandledRejection', (reason) => {
|
|
103
|
+
if (reason instanceof RelqError) {
|
|
104
|
+
console.error(formatRelqError(reason));
|
|
105
|
+
}
|
|
106
|
+
else if (reason instanceof Error) {
|
|
107
|
+
console.error(`${reason.name || 'Error'}: ${reason.message}`);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.error('Unhandled rejection:', reason);
|
|
111
|
+
}
|
|
112
|
+
node_process_1.default.exit(1);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
60
115
|
class RelqError extends Error {
|
|
61
116
|
name;
|
|
62
|
-
cause;
|
|
63
117
|
timestamp;
|
|
64
118
|
constructor(message, cause) {
|
|
65
119
|
super(message);
|
|
66
120
|
this.name = 'RelqError';
|
|
67
|
-
this
|
|
121
|
+
Object.defineProperty(this, ORIGINAL_ERROR, {
|
|
122
|
+
value: cause,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
writable: false,
|
|
125
|
+
});
|
|
68
126
|
this.timestamp = new Date();
|
|
127
|
+
_autoInstallErrorHandler();
|
|
69
128
|
if (Error.captureStackTrace) {
|
|
70
129
|
Error.captureStackTrace(this, this.constructor);
|
|
71
130
|
}
|
|
131
|
+
if (this.stack) {
|
|
132
|
+
const lines = this.stack.split('\n');
|
|
133
|
+
this.stack = lines.filter(line => line.includes(this.name) ||
|
|
134
|
+
line.trim().startsWith('at ') ||
|
|
135
|
+
line.trim() === '').slice(0, 8).join('\n');
|
|
136
|
+
}
|
|
72
137
|
}
|
|
73
138
|
[Symbol.for('nodejs.util.inspect.custom')](_depth, _options) {
|
|
74
139
|
const lines = [
|
|
75
|
-
|
|
76
|
-
`
|
|
140
|
+
'',
|
|
141
|
+
` \x1b[1m\x1b[31m${this.name}\x1b[0m: ${this.message}`,
|
|
77
142
|
];
|
|
78
143
|
const props = this._getInspectProps();
|
|
79
144
|
for (const [key, value] of Object.entries(props)) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const stackLines = this.stack.split('\n').filter(line => line.trim().startsWith('at ') || line.includes(this.name));
|
|
85
|
-
lines.push('');
|
|
86
|
-
lines.push(...stackLines.slice(1, 6));
|
|
145
|
+
if (value === undefined)
|
|
146
|
+
continue;
|
|
147
|
+
const strVal = typeof value === 'string' ? value : JSON.stringify(value);
|
|
148
|
+
lines.push(` \x1b[2m${key.padStart(16)}:\x1b[0m ${strVal}`);
|
|
87
149
|
}
|
|
150
|
+
lines.push(` \x1b[2m timestamp:\x1b[0m ${this.timestamp.toISOString()}`);
|
|
151
|
+
lines.push('');
|
|
88
152
|
return lines.join('\n');
|
|
89
153
|
}
|
|
90
154
|
_getInspectProps() {
|
|
@@ -94,13 +158,15 @@ class RelqError extends Error {
|
|
|
94
158
|
return {
|
|
95
159
|
name: this.name,
|
|
96
160
|
message: this.message,
|
|
97
|
-
cause: this.cause?.message,
|
|
98
161
|
timestamp: this.timestamp.toISOString(),
|
|
99
|
-
|
|
162
|
+
...this._getInspectProps(),
|
|
100
163
|
};
|
|
101
164
|
}
|
|
102
165
|
}
|
|
103
166
|
exports.RelqError = RelqError;
|
|
167
|
+
function getOriginalError(error) {
|
|
168
|
+
return error[ORIGINAL_ERROR];
|
|
169
|
+
}
|
|
104
170
|
class RelqConnectionError extends RelqError {
|
|
105
171
|
name = 'RelqConnectionError';
|
|
106
172
|
code;
|
|
@@ -284,9 +350,143 @@ class RelqBuilderError extends RelqError {
|
|
|
284
350
|
}
|
|
285
351
|
}
|
|
286
352
|
exports.RelqBuilderError = RelqBuilderError;
|
|
353
|
+
class RelqConstraintError extends RelqError {
|
|
354
|
+
name = 'RelqConstraintError';
|
|
355
|
+
constraintType;
|
|
356
|
+
table;
|
|
357
|
+
column;
|
|
358
|
+
constraint;
|
|
359
|
+
value;
|
|
360
|
+
sql;
|
|
361
|
+
code;
|
|
362
|
+
detail;
|
|
363
|
+
retryable = false;
|
|
364
|
+
constructor(message, constraintType, options) {
|
|
365
|
+
super(message, options?.cause);
|
|
366
|
+
this.constraintType = constraintType;
|
|
367
|
+
this.table = options?.table;
|
|
368
|
+
this.column = options?.column;
|
|
369
|
+
this.constraint = options?.constraint;
|
|
370
|
+
this.value = options?.value;
|
|
371
|
+
this.sql = options?.sql;
|
|
372
|
+
this.code = options?.code;
|
|
373
|
+
this.detail = options?.detail;
|
|
374
|
+
}
|
|
375
|
+
_getInspectProps() {
|
|
376
|
+
return {
|
|
377
|
+
constraintType: this.constraintType,
|
|
378
|
+
table: this.table,
|
|
379
|
+
column: this.column,
|
|
380
|
+
constraint: this.constraint,
|
|
381
|
+
value: this.value,
|
|
382
|
+
code: this.code,
|
|
383
|
+
detail: this.detail,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
toJSON() {
|
|
387
|
+
return {
|
|
388
|
+
...super.toJSON(),
|
|
389
|
+
constraintType: this.constraintType,
|
|
390
|
+
table: this.table,
|
|
391
|
+
column: this.column,
|
|
392
|
+
constraint: this.constraint,
|
|
393
|
+
value: this.value,
|
|
394
|
+
sql: this.sql,
|
|
395
|
+
code: this.code,
|
|
396
|
+
detail: this.detail,
|
|
397
|
+
retryable: this.retryable,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.RelqConstraintError = RelqConstraintError;
|
|
402
|
+
class RelqSchemaError extends RelqError {
|
|
403
|
+
name = 'RelqSchemaError';
|
|
404
|
+
schemaObject;
|
|
405
|
+
objectName;
|
|
406
|
+
table;
|
|
407
|
+
sql;
|
|
408
|
+
code;
|
|
409
|
+
hint;
|
|
410
|
+
constructor(message, schemaObject, options) {
|
|
411
|
+
super(message, options?.cause);
|
|
412
|
+
this.schemaObject = schemaObject;
|
|
413
|
+
this.objectName = options?.objectName;
|
|
414
|
+
this.table = options?.table;
|
|
415
|
+
this.sql = options?.sql;
|
|
416
|
+
this.code = options?.code;
|
|
417
|
+
this.hint = options?.hint;
|
|
418
|
+
}
|
|
419
|
+
_getInspectProps() {
|
|
420
|
+
return { schemaObject: this.schemaObject, objectName: this.objectName, table: this.table, code: this.code, hint: this.hint };
|
|
421
|
+
}
|
|
422
|
+
toJSON() {
|
|
423
|
+
return { ...super.toJSON(), schemaObject: this.schemaObject, objectName: this.objectName, table: this.table, sql: this.sql, code: this.code, hint: this.hint };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.RelqSchemaError = RelqSchemaError;
|
|
427
|
+
class RelqDataError extends RelqError {
|
|
428
|
+
name = 'RelqDataError';
|
|
429
|
+
dataIssue;
|
|
430
|
+
column;
|
|
431
|
+
table;
|
|
432
|
+
value;
|
|
433
|
+
dataType;
|
|
434
|
+
sql;
|
|
435
|
+
code;
|
|
436
|
+
constructor(message, dataIssue, options) {
|
|
437
|
+
super(message, options?.cause);
|
|
438
|
+
this.dataIssue = dataIssue;
|
|
439
|
+
this.column = options?.column;
|
|
440
|
+
this.table = options?.table;
|
|
441
|
+
this.value = options?.value;
|
|
442
|
+
this.dataType = options?.dataType;
|
|
443
|
+
this.sql = options?.sql;
|
|
444
|
+
this.code = options?.code;
|
|
445
|
+
}
|
|
446
|
+
_getInspectProps() {
|
|
447
|
+
return { dataIssue: this.dataIssue, column: this.column, table: this.table, dataType: this.dataType, code: this.code };
|
|
448
|
+
}
|
|
449
|
+
toJSON() {
|
|
450
|
+
return { ...super.toJSON(), dataIssue: this.dataIssue, column: this.column, table: this.table, value: this.value, dataType: this.dataType, sql: this.sql, code: this.code };
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
exports.RelqDataError = RelqDataError;
|
|
454
|
+
class RelqLockError extends RelqError {
|
|
455
|
+
name = 'RelqLockError';
|
|
456
|
+
lockIssue;
|
|
457
|
+
sql;
|
|
458
|
+
code;
|
|
459
|
+
retryable;
|
|
460
|
+
constructor(message, lockIssue, options) {
|
|
461
|
+
super(message, options?.cause);
|
|
462
|
+
this.lockIssue = lockIssue;
|
|
463
|
+
this.sql = options?.sql;
|
|
464
|
+
this.code = options?.code;
|
|
465
|
+
this.retryable = lockIssue === 'deadlock' || lockIssue === 'serialization_failure';
|
|
466
|
+
}
|
|
467
|
+
_getInspectProps() {
|
|
468
|
+
return { lockIssue: this.lockIssue, retryable: this.retryable, code: this.code };
|
|
469
|
+
}
|
|
470
|
+
toJSON() {
|
|
471
|
+
return { ...super.toJSON(), lockIssue: this.lockIssue, sql: this.sql, code: this.code, retryable: this.retryable };
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
exports.RelqLockError = RelqLockError;
|
|
287
475
|
function isRelqError(error) {
|
|
288
476
|
return error instanceof RelqError;
|
|
289
477
|
}
|
|
478
|
+
function isRelqConstraintError(error) {
|
|
479
|
+
return error instanceof RelqConstraintError;
|
|
480
|
+
}
|
|
481
|
+
function isRelqSchemaError(error) {
|
|
482
|
+
return error instanceof RelqSchemaError;
|
|
483
|
+
}
|
|
484
|
+
function isRelqDataError(error) {
|
|
485
|
+
return error instanceof RelqDataError;
|
|
486
|
+
}
|
|
487
|
+
function isRelqLockError(error) {
|
|
488
|
+
return error instanceof RelqLockError;
|
|
489
|
+
}
|
|
290
490
|
function isRelqConnectionError(error) {
|
|
291
491
|
return error instanceof RelqConnectionError;
|
|
292
492
|
}
|
|
@@ -309,48 +509,309 @@ function wrapError(error, context) {
|
|
|
309
509
|
: String(error);
|
|
310
510
|
return new RelqError(message);
|
|
311
511
|
}
|
|
312
|
-
function parsePostgresError(error, sql) {
|
|
512
|
+
function parsePostgresError(error, sql, isBuilder = true) {
|
|
313
513
|
const message = error.message || 'Database error';
|
|
314
514
|
const code = error.code;
|
|
315
515
|
if (isNetworkErrorCode(code)) {
|
|
316
516
|
return new RelqConnectionError(message, {
|
|
317
|
-
cause: error,
|
|
318
|
-
code,
|
|
319
|
-
host: error.hostname || error.address,
|
|
320
|
-
port: error.port
|
|
517
|
+
cause: error, code, host: error.hostname || error.address, port: error.port
|
|
321
518
|
});
|
|
322
519
|
}
|
|
323
|
-
if (code === '57P01' || code === '57P03' || code === '08006' || code === '08001' || code === '08004') {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
520
|
+
if (code === '57P01' || code === '57P03' || code === '08006' || code === '08001' || code === '08004' || code === '08000' || code === '08003') {
|
|
521
|
+
const friendlyMessages = {
|
|
522
|
+
'57P01': 'Database server is shutting down.',
|
|
523
|
+
'57P03': 'Database server is starting up — try again in a moment.',
|
|
524
|
+
'08006': 'Connection to database was lost during the query.',
|
|
525
|
+
'08001': 'Cannot connect to database server. Check your host, port, and credentials.',
|
|
526
|
+
'08004': 'Database server rejected the connection. You may have reached the connection limit.',
|
|
527
|
+
'08000': 'Database connection failed.',
|
|
528
|
+
'08003': 'Database connection does not exist. The connection may have been dropped.',
|
|
529
|
+
};
|
|
530
|
+
return new RelqConnectionError(friendlyMessages[code] || message, {
|
|
531
|
+
cause: error, code, host: error.hostname, port: error.port
|
|
329
532
|
});
|
|
330
533
|
}
|
|
534
|
+
if (code === '53300') {
|
|
535
|
+
return new RelqConnectionError('Too many database connections. The server has reached its connection limit. Try again later or increase max_connections.', { cause: error, code });
|
|
536
|
+
}
|
|
331
537
|
if (code === '57014') {
|
|
332
|
-
return new RelqTimeoutError('Query execution timed out', error.timeout || 0, 'query', error);
|
|
538
|
+
return new RelqTimeoutError('Query execution timed out.', error.timeout || 0, 'query', error);
|
|
333
539
|
}
|
|
334
540
|
if (message.includes('timeout exceeded when trying to connect')) {
|
|
335
|
-
return new RelqTimeoutError('Connection timed out', error.timeout || 0, 'connection', error);
|
|
541
|
+
return new RelqTimeoutError('Connection timed out.', error.timeout || 0, 'connection', error);
|
|
336
542
|
}
|
|
337
543
|
if (!code && (message.includes('Connection terminated') ||
|
|
338
544
|
message.includes('connection is closed') ||
|
|
339
545
|
message.includes('Client has encountered a connection error'))) {
|
|
340
546
|
return new RelqConnectionError(message, {
|
|
341
|
-
cause: error,
|
|
342
|
-
|
|
343
|
-
|
|
547
|
+
cause: error, host: error.hostname || error.address, port: error.port
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
if (!isBuilder) {
|
|
551
|
+
return new RelqQueryError(message, { cause: error, sql, code, detail: error.detail, hint: error.hint });
|
|
552
|
+
}
|
|
553
|
+
if (code === '23505') {
|
|
554
|
+
const valueMatch = error.detail?.match(/Key \((.+?)\)=\((.+?)\) already exists/);
|
|
555
|
+
const col = valueMatch?.[1] || error.column;
|
|
556
|
+
const val = valueMatch?.[2];
|
|
557
|
+
return new RelqConstraintError(`Duplicate value: A record with this ${col || 'value'} already exists.${val ? ` Value: "${val}".` : ''}${error.constraint ? ` Constraint: "${error.constraint}".` : ''}`, 'unique', { cause: error, table: error.table, column: col, constraint: error.constraint, value: val, sql, code, detail: error.detail });
|
|
558
|
+
}
|
|
559
|
+
if (code === '23503') {
|
|
560
|
+
const isDelete = error.detail?.includes('is still referenced from table');
|
|
561
|
+
const refMatch = error.detail?.match(/(?:table|from table) "(\w+)"/);
|
|
562
|
+
const refTable = refMatch?.[1];
|
|
563
|
+
const msg = isDelete
|
|
564
|
+
? `Cannot delete: This record is still referenced by "${refTable || 'another table'}".${error.constraint ? ` Constraint: "${error.constraint}".` : ''}`
|
|
565
|
+
: `Referenced record not found: The value you're inserting references a record in "${refTable || 'another table'}" that doesn't exist.${error.constraint ? ` Constraint: "${error.constraint}".` : ''}`;
|
|
566
|
+
return new RelqConstraintError(msg, 'foreign_key', {
|
|
567
|
+
cause: error, table: error.table, constraint: error.constraint, sql, code, detail: error.detail
|
|
344
568
|
});
|
|
345
569
|
}
|
|
570
|
+
if (code === '23502') {
|
|
571
|
+
return new RelqConstraintError(`Required field missing: Column "${error.column || 'unknown'}" on table "${error.table || 'unknown'}" cannot be NULL. Provide a value or set a default in your schema.`, 'not_null', { cause: error, table: error.table, column: error.column, sql, code, detail: error.detail });
|
|
572
|
+
}
|
|
573
|
+
if (code === '23514') {
|
|
574
|
+
return new RelqConstraintError(`Check constraint failed: "${error.constraint || 'unknown'}" on table "${error.table || 'unknown'}". The value doesn't satisfy the validation rule.`, 'check', { cause: error, table: error.table, constraint: error.constraint, sql, code, detail: error.detail });
|
|
575
|
+
}
|
|
576
|
+
if (code === '23P01') {
|
|
577
|
+
return new RelqConstraintError(`Exclusion constraint failed: "${error.constraint || 'unknown'}" on table "${error.table || 'unknown'}". A conflicting record exists.`, 'exclusion', { cause: error, table: error.table, constraint: error.constraint, sql, code, detail: error.detail });
|
|
578
|
+
}
|
|
579
|
+
if (code === '23001') {
|
|
580
|
+
return new RelqConstraintError(`Restrict violation: Cannot delete or update — a RESTRICT constraint prevents this operation.`, 'restrict', { cause: error, table: error.table, constraint: error.constraint, sql, code, detail: error.detail });
|
|
581
|
+
}
|
|
582
|
+
if (code === '23000') {
|
|
583
|
+
return new RelqConstraintError(`Integrity constraint violation: ${error.detail || message}.${error.constraint ? ` Constraint: "${error.constraint}".` : ''}`, 'unique', { cause: error, table: error.table, constraint: error.constraint, sql, code, detail: error.detail });
|
|
584
|
+
}
|
|
585
|
+
if (code === '40003') {
|
|
586
|
+
return new RelqLockError('Ambiguous result: The transaction outcome is unknown (network issue during COMMIT). Check if the transaction was applied and retry if needed.', 'serialization_failure', { cause: error, sql, code });
|
|
587
|
+
}
|
|
588
|
+
if (code === '40P01') {
|
|
589
|
+
return new RelqLockError('Deadlock detected: Two transactions are waiting for each other. Retry the transaction.', 'deadlock', { cause: error, sql, code });
|
|
590
|
+
}
|
|
591
|
+
if (code === '40001') {
|
|
592
|
+
return new RelqLockError('Serialization conflict: Another transaction modified the same data. Retry the transaction.', 'serialization_failure', { cause: error, sql, code });
|
|
593
|
+
}
|
|
594
|
+
if (code === '55P03') {
|
|
595
|
+
return new RelqLockError('Lock not available: Another transaction holds the lock and NOWAIT was specified. Retry or remove NOWAIT.', 'lock_not_available', { cause: error, sql, code });
|
|
596
|
+
}
|
|
597
|
+
if (code === '42P01') {
|
|
598
|
+
return new RelqSchemaError(`Table "${error.table || extractFromMessage(message, /relation "(.+?)"/)}" does not exist. Check your schema definition or run migrations.`, 'table', { cause: error, objectName: error.table, sql, code });
|
|
599
|
+
}
|
|
600
|
+
if (code === '42703') {
|
|
601
|
+
const col = error.column || extractFromMessage(message, /column "(.+?)"/);
|
|
602
|
+
return new RelqSchemaError(`Column "${col}" does not exist. Check column name spelling in your schema and query.`, 'column', { cause: error, objectName: col, table: error.table, sql, code });
|
|
603
|
+
}
|
|
604
|
+
if (code === '42803') {
|
|
605
|
+
const col = extractFromMessage(message, /column "(.+?)"/);
|
|
606
|
+
return new RelqSchemaError(`Grouping error: Column "${col || 'unknown'}" must be in GROUP BY or used in an aggregate function. Add it to .groupBy() or wrap it in .include() with an aggregate.`, 'column', { cause: error, objectName: col, sql, code, hint: 'Add the column to .groupBy() or use it inside .include() with a.count(), a.sum(), etc.' });
|
|
607
|
+
}
|
|
608
|
+
if (code === '42883') {
|
|
609
|
+
const fnMatch = message.match(/function (\w+)\((\w+)\)/);
|
|
610
|
+
const fnName = fnMatch?.[1];
|
|
611
|
+
const argType = fnMatch?.[2];
|
|
612
|
+
if (fnName === 'bool_and' || fnName === 'bool_or') {
|
|
613
|
+
const relqMethod = fnName === 'bool_and' ? 'boolAnd' : 'boolOr';
|
|
614
|
+
return new RelqSchemaError(`${relqMethod}() only accepts boolean columns, but received a ${argType || 'non-boolean'} column. Pass a boolean column like t.table.isActive or t.table.delivered.`, 'function', { cause: error, sql, code, hint: `Change a.${relqMethod}(t.table.numericColumn) to a.${relqMethod}(t.table.booleanColumn)` });
|
|
615
|
+
}
|
|
616
|
+
if (fnName === 'string_agg') {
|
|
617
|
+
return new RelqSchemaError(`stringAgg() received an incompatible column type (${argType || 'unknown'}). The column should be a text/string type.`, 'function', { cause: error, sql, code, hint: 'stringAgg auto-casts to text — if you see this error, the column type may not support text conversion.' });
|
|
618
|
+
}
|
|
619
|
+
return new RelqSchemaError(`Function not found: ${message}. Check function name and argument types.`, 'function', { cause: error, sql, code });
|
|
620
|
+
}
|
|
621
|
+
if (code === '42804' || code === '42846') {
|
|
622
|
+
return new RelqSchemaError(`Type mismatch: ${message}. Check that the value type matches the column type.`, 'type', { cause: error, sql, code });
|
|
623
|
+
}
|
|
624
|
+
if (code === '42601') {
|
|
625
|
+
return new RelqSchemaError(`SQL syntax error: ${message}. This may indicate a bug in the query builder — please report it.`, 'column', { cause: error, sql, code, hint: 'If you are using db.raw(), check your SQL syntax.' });
|
|
626
|
+
}
|
|
627
|
+
if (code === '428C9') {
|
|
628
|
+
return new RelqSchemaError(`Cannot write to generated column. Remove it from your insert or update data — generated columns are computed by the database.`, 'column', { cause: error, objectName: error.column, table: error.table, sql, code });
|
|
629
|
+
}
|
|
630
|
+
if (code === '42P07') {
|
|
631
|
+
return new RelqSchemaError(`Table "${error.table || extractFromMessage(message, /relation "(.+?)"/)}" already exists.`, 'table', { cause: error, objectName: error.table, sql, code });
|
|
632
|
+
}
|
|
633
|
+
if (code === '42501') {
|
|
634
|
+
return new RelqSchemaError(`Permission denied: ${message}. Check that your database user has the required privileges.`, 'table', { cause: error, table: error.table, sql, code });
|
|
635
|
+
}
|
|
636
|
+
if (code === '42702') {
|
|
637
|
+
const col = extractFromMessage(message, /column "(.+?)"/);
|
|
638
|
+
return new RelqSchemaError(`Ambiguous column "${col || 'unknown'}": The column exists in multiple tables. Qualify it with a table name or alias.`, 'column', { cause: error, objectName: col, sql, code, hint: 'When joining tables, use the table alias to qualify ambiguous columns.' });
|
|
639
|
+
}
|
|
640
|
+
if (code === '42830') {
|
|
641
|
+
return new RelqSchemaError(`Invalid foreign key definition: ${message}.`, 'constraint', { cause: error, sql, code });
|
|
642
|
+
}
|
|
643
|
+
if (code === '42701') {
|
|
644
|
+
const col = extractFromMessage(message, /column "(.+?)"/);
|
|
645
|
+
return new RelqSchemaError(`Duplicate column "${col || 'unknown'}": A column with this name already exists.`, 'column', { cause: error, objectName: col, table: error.table, sql, code });
|
|
646
|
+
}
|
|
647
|
+
if (code === '42P02') {
|
|
648
|
+
return new RelqSchemaError(`Undefined parameter: ${message}. Check that the number of parameters matches the placeholders in your query.`, 'column', { cause: error, sql, code });
|
|
649
|
+
}
|
|
650
|
+
if (code === '42704') {
|
|
651
|
+
const obj = extractFromMessage(message, /type "(.+?)"/) || extractFromMessage(message, /"(.+?)"/);
|
|
652
|
+
return new RelqSchemaError(`Object "${obj || 'unknown'}" does not exist: ${message}`, 'type', { cause: error, objectName: obj, sql, code });
|
|
653
|
+
}
|
|
654
|
+
if (code === '42P04') {
|
|
655
|
+
const db = extractFromMessage(message, /database "(.+?)"/);
|
|
656
|
+
return new RelqSchemaError(`Database "${db || 'unknown'}" already exists.`, 'schema', { cause: error, objectName: db, sql, code });
|
|
657
|
+
}
|
|
658
|
+
if (code === '42P06') {
|
|
659
|
+
const schema = extractFromMessage(message, /schema "(.+?)"/);
|
|
660
|
+
return new RelqSchemaError(`Schema "${schema || 'unknown'}" already exists.`, 'schema', { cause: error, objectName: schema, sql, code });
|
|
661
|
+
}
|
|
662
|
+
if (code === '42710') {
|
|
663
|
+
const obj = extractFromMessage(message, /"(.+?)"/);
|
|
664
|
+
return new RelqSchemaError(`Object "${obj || 'unknown'}" already exists: ${message}`, 'type', { cause: error, objectName: obj, sql, code });
|
|
665
|
+
}
|
|
666
|
+
if (code === '42809') {
|
|
667
|
+
return new RelqSchemaError(`Wrong object type: ${message}. The object exists but is not the expected type (e.g., using a view as a table).`, 'type', { cause: error, sql, code });
|
|
668
|
+
}
|
|
669
|
+
if (code === '42P18') {
|
|
670
|
+
return new RelqSchemaError(`Cannot determine data type: ${message}. Add an explicit type cast.`, 'type', { cause: error, sql, code, hint: 'TypeScript types are correct but the database needs a type hint. This usually happens with NULL or ambiguous literals.' });
|
|
671
|
+
}
|
|
672
|
+
if (code === '42P20') {
|
|
673
|
+
return new RelqSchemaError(`Window function error: ${message}.`, 'function', { cause: error, sql, code });
|
|
674
|
+
}
|
|
675
|
+
if (code === '42P19') {
|
|
676
|
+
return new RelqSchemaError(`Invalid recursion: ${message}. Check your CTE recursive query.`, 'function', { cause: error, sql, code });
|
|
677
|
+
}
|
|
678
|
+
if (code === '42622') {
|
|
679
|
+
return new RelqSchemaError(`Name too long: ${message}. PostgreSQL identifiers are limited to 63 characters.`, 'column', { cause: error, sql, code });
|
|
680
|
+
}
|
|
681
|
+
if (code === '42939') {
|
|
682
|
+
return new RelqSchemaError(`Reserved name: ${message}. The name conflicts with a PostgreSQL reserved word.`, 'column', { cause: error, sql, code, hint: 'Rename the column/table or quote the identifier.' });
|
|
683
|
+
}
|
|
684
|
+
if (code === '42602') {
|
|
685
|
+
return new RelqSchemaError(`Invalid name: ${message}. The identifier contains invalid characters.`, 'column', { cause: error, sql, code });
|
|
686
|
+
}
|
|
687
|
+
if (code === '42P10') {
|
|
688
|
+
return new RelqSchemaError(`Invalid column reference: ${message}. The column cannot be used in this context.`, 'column', { cause: error, sql, code });
|
|
689
|
+
}
|
|
690
|
+
if (code === '42611') {
|
|
691
|
+
return new RelqSchemaError(`Invalid column definition: ${message}.`, 'column', { cause: error, sql, code });
|
|
692
|
+
}
|
|
693
|
+
if (code === '42P16') {
|
|
694
|
+
return new RelqSchemaError(`Invalid table definition: ${message}.`, 'table', { cause: error, sql, code });
|
|
695
|
+
}
|
|
696
|
+
if (code === '42P17') {
|
|
697
|
+
return new RelqSchemaError(`Invalid object definition: ${message}.`, 'type', { cause: error, sql, code });
|
|
698
|
+
}
|
|
699
|
+
if (code === '42725') {
|
|
700
|
+
return new RelqSchemaError(`Ambiguous function: ${message}. Multiple functions match the given name and argument types.`, 'function', { cause: error, sql, code, hint: 'Add explicit type casts to the arguments to resolve ambiguity.' });
|
|
701
|
+
}
|
|
702
|
+
if (code === '42P21' || code === '42P22') {
|
|
703
|
+
return new RelqSchemaError(`Collation mismatch: ${message}. The columns use different collations.`, 'column', { cause: error, sql, code });
|
|
704
|
+
}
|
|
705
|
+
if (code?.startsWith('42')) {
|
|
706
|
+
return new RelqSchemaError(`Schema/syntax error: ${message}`, 'type', { cause: error, sql, code });
|
|
707
|
+
}
|
|
708
|
+
if (code === '28000' || code === '28P01') {
|
|
709
|
+
return new RelqConnectionError(`Authentication failed: ${code === '28P01' ? 'Invalid password.' : 'Invalid authorization.'} Check your database credentials.`, { cause: error, code });
|
|
710
|
+
}
|
|
711
|
+
if (code === '3D000') {
|
|
712
|
+
const db = extractFromMessage(message, /database "(.+?)"/);
|
|
713
|
+
return new RelqSchemaError(`Database "${db || 'unknown'}" does not exist. Check your database name in the connection config.`, 'schema', { cause: error, objectName: db, sql, code });
|
|
714
|
+
}
|
|
715
|
+
if (code === '3F000') {
|
|
716
|
+
const schema = extractFromMessage(message, /schema "(.+?)"/);
|
|
717
|
+
return new RelqSchemaError(`Schema "${schema || 'unknown'}" does not exist. Check the schema name in your config.`, 'schema', { cause: error, objectName: schema, sql, code });
|
|
718
|
+
}
|
|
719
|
+
if (code === '25001') {
|
|
720
|
+
return new RelqTransactionError('A transaction is already active. Nested transactions are not supported — use savepoints instead.', 'BEGIN', { cause: error, transactionState: 'active' });
|
|
721
|
+
}
|
|
722
|
+
if (code === '25P01') {
|
|
723
|
+
return new RelqTransactionError('No active transaction. You tried to COMMIT or ROLLBACK but there is no transaction in progress.', 'COMMIT', { cause: error, transactionState: 'none' });
|
|
724
|
+
}
|
|
725
|
+
if (code === '25P03') {
|
|
726
|
+
return new RelqTimeoutError('Idle transaction timeout: The transaction was idle for too long and was terminated by the server.', 0, 'query', error);
|
|
727
|
+
}
|
|
728
|
+
if (code === 'OC000') {
|
|
729
|
+
return new RelqLockError('Transaction conflict (DSQL): Another transaction modified the same data. Retry the transaction.', 'serialization_failure', { cause: error, sql, code });
|
|
730
|
+
}
|
|
731
|
+
if (code === 'OC001') {
|
|
732
|
+
return new RelqSchemaError('Schema conflict (DSQL): The schema was updated by another transaction. Retry the operation.', 'schema', { cause: error, sql, code });
|
|
733
|
+
}
|
|
734
|
+
if (code === '53100') {
|
|
735
|
+
return new RelqQueryError('Disk full: The server has run out of disk space.', { cause: error, sql, code });
|
|
736
|
+
}
|
|
737
|
+
if (code === '54001') {
|
|
738
|
+
return new RelqQueryError('Statement too complex: Simplify the query or break it into smaller parts.', { cause: error, sql, code });
|
|
739
|
+
}
|
|
740
|
+
if (code === '0A000') {
|
|
741
|
+
return new RelqSchemaError(`Feature not supported: ${message}. This feature may not be available on your database dialect.`, 'type', { cause: error, sql, code, hint: 'Check your dialect\'s supported features.' });
|
|
742
|
+
}
|
|
743
|
+
if (code === '22001') {
|
|
744
|
+
return new RelqDataError(`Value too long for column "${error.column || 'unknown'}". Shorten the value or increase the column length in your schema.`, 'too_long', { cause: error, column: error.column, table: error.table, sql, code });
|
|
745
|
+
}
|
|
746
|
+
if (code === '22003') {
|
|
747
|
+
return new RelqDataError(`Numeric value out of range for column "${error.column || 'unknown'}". The number is too large or too small for the column type.`, 'out_of_range', { cause: error, column: error.column, table: error.table, sql, code });
|
|
748
|
+
}
|
|
749
|
+
if (code === '22P02') {
|
|
750
|
+
return new RelqDataError(`Invalid value: Cannot convert the given value to the expected type. ${error.detail || message}`, 'invalid_type', { cause: error, dataType: error.dataType, sql, code });
|
|
751
|
+
}
|
|
752
|
+
if (code === '22007' || code === '22008') {
|
|
753
|
+
return new RelqDataError(`Invalid date/time value: ${error.detail || message}. Check date format and range.`, 'invalid_format', { cause: error, sql, code });
|
|
754
|
+
}
|
|
755
|
+
if (code === '22012') {
|
|
756
|
+
return new RelqDataError('Division by zero in query.', 'division_by_zero', { cause: error, sql, code });
|
|
757
|
+
}
|
|
758
|
+
if (code === '22004') {
|
|
759
|
+
return new RelqDataError(`Null value not allowed in this context. ${error.detail || message}`, 'null_not_allowed', { cause: error, column: error.column, table: error.table, sql, code });
|
|
760
|
+
}
|
|
761
|
+
if (code === '22023') {
|
|
762
|
+
return new RelqDataError(`Invalid parameter value: ${error.detail || message}`, 'invalid_type', { cause: error, sql, code });
|
|
763
|
+
}
|
|
764
|
+
if (code === '22018') {
|
|
765
|
+
return new RelqDataError(`Invalid value for type cast: ${error.detail || message}. Cannot convert the value to the target type.`, 'invalid_type', { cause: error, dataType: error.dataType, sql, code });
|
|
766
|
+
}
|
|
767
|
+
if (code === '2200H') {
|
|
768
|
+
return new RelqDataError(`Sequence limit exceeded. The sequence has reached its maximum value.`, 'out_of_range', { cause: error, sql, code });
|
|
769
|
+
}
|
|
770
|
+
if (code === '25P02') {
|
|
771
|
+
return new RelqTransactionError('Transaction is in a failed state. A previous error in this transaction makes it unusable. The transaction will be rolled back.', 'ROLLBACK', { cause: error, transactionState: 'failed' });
|
|
772
|
+
}
|
|
773
|
+
if (code === '25006') {
|
|
774
|
+
return new RelqTransactionError('Cannot write data in a read-only transaction. Remove the readOnly option or use a separate transaction for writes.', 'COMMIT', { cause: error, transactionState: 'read_only' });
|
|
775
|
+
}
|
|
776
|
+
if (code === '53200') {
|
|
777
|
+
return new RelqQueryError('Out of memory: The query requires too much memory. Try reducing result size with LIMIT or simplifying the query.', {
|
|
778
|
+
cause: error, sql, code
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
if (code?.startsWith('22')) {
|
|
782
|
+
return new RelqDataError(`Data error: ${message}`, 'invalid_type', { cause: error, sql, code });
|
|
783
|
+
}
|
|
784
|
+
if (code?.startsWith('23')) {
|
|
785
|
+
return new RelqConstraintError(`Constraint violation: ${message}`, 'unique', { cause: error, table: error.table, constraint: error.constraint, sql, code, detail: error.detail });
|
|
786
|
+
}
|
|
787
|
+
if (code?.startsWith('25')) {
|
|
788
|
+
return new RelqTransactionError(`Transaction error: ${message}`, 'ROLLBACK', { cause: error });
|
|
789
|
+
}
|
|
790
|
+
if (code?.startsWith('40')) {
|
|
791
|
+
return new RelqLockError(`Transaction rollback: ${message}. Retry the transaction.`, 'serialization_failure', { cause: error, sql, code });
|
|
792
|
+
}
|
|
793
|
+
if (code?.startsWith('53')) {
|
|
794
|
+
return new RelqQueryError(`Resource limit: ${message}`, { cause: error, sql, code });
|
|
795
|
+
}
|
|
796
|
+
if (code?.startsWith('54')) {
|
|
797
|
+
return new RelqQueryError(`Limit exceeded: ${message}`, { cause: error, sql, code });
|
|
798
|
+
}
|
|
799
|
+
if (code?.startsWith('55')) {
|
|
800
|
+
return new RelqQueryError(`Object state error: ${message}`, { cause: error, sql, code });
|
|
801
|
+
}
|
|
802
|
+
if (code?.startsWith('57')) {
|
|
803
|
+
return new RelqConnectionError(`Server intervention: ${message}`, { cause: error, code });
|
|
804
|
+
}
|
|
805
|
+
if (code?.startsWith('08')) {
|
|
806
|
+
return new RelqConnectionError(`Connection error: ${message}`, { cause: error, code });
|
|
807
|
+
}
|
|
346
808
|
return new RelqQueryError(message, {
|
|
347
|
-
cause: error,
|
|
348
|
-
sql,
|
|
349
|
-
code,
|
|
350
|
-
detail: error.detail,
|
|
351
|
-
hint: error.hint
|
|
809
|
+
cause: error, sql, code, detail: error.detail, hint: error.hint
|
|
352
810
|
});
|
|
353
811
|
}
|
|
812
|
+
function extractFromMessage(message, pattern) {
|
|
813
|
+
return message.match(pattern)?.[1];
|
|
814
|
+
}
|
|
354
815
|
const NETWORK_ERROR_CODES = new Set([
|
|
355
816
|
'ECONNREFUSED', 'ECONNRESET', 'ENOTFOUND', 'ESERVFAIL',
|
|
356
817
|
'ETIMEDOUT', 'EPIPE', 'EAI_AGAIN', 'EHOSTUNREACH',
|
|
@@ -3,14 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isPoolingEnabled = isPoolingEnabled;
|
|
4
4
|
exports.toPoolConfig = toPoolConfig;
|
|
5
5
|
exports.isAwsDsqlConfig = isAwsDsqlConfig;
|
|
6
|
-
|
|
6
|
+
function mergeWithDefaults(userConfig) {
|
|
7
|
+
return {
|
|
8
|
+
min: userConfig?.min ?? 0,
|
|
9
|
+
max: userConfig?.max ?? 10,
|
|
10
|
+
idleTimeoutMillis: userConfig?.idleTimeoutMillis ?? 30000,
|
|
11
|
+
connectionTimeoutMillis: userConfig?.connectionTimeoutMillis ?? 10000,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
7
14
|
function isPoolingEnabled(config) {
|
|
8
15
|
return config.pooling !== false;
|
|
9
16
|
}
|
|
10
17
|
function toPoolConfig(config) {
|
|
11
18
|
const smartDefaults = config.disableSmartDefaults
|
|
12
19
|
? { min: 0, max: 10, idleTimeoutMillis: 30000, connectionTimeoutMillis: 0 }
|
|
13
|
-
:
|
|
20
|
+
: mergeWithDefaults(config.pool);
|
|
14
21
|
const isAws = !!config.aws;
|
|
15
22
|
const host = isAws ? config.aws.hostname : (config.host || 'localhost');
|
|
16
23
|
const port = config.aws?.port ?? config.port ?? 5432;
|
|
@@ -32,9 +39,9 @@ function toPoolConfig(config) {
|
|
|
32
39
|
ssl: config.pool?.ssl ?? ssl,
|
|
33
40
|
allowExitOnIdle
|
|
34
41
|
};
|
|
35
|
-
if (config.
|
|
42
|
+
if (config.url) {
|
|
36
43
|
return {
|
|
37
|
-
connectionString: config.
|
|
44
|
+
connectionString: config.url,
|
|
38
45
|
min: poolConfig.min,
|
|
39
46
|
max: poolConfig.max,
|
|
40
47
|
idleTimeoutMillis: poolConfig.idleTimeoutMillis,
|