@relq/orm 0.1.3 → 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 +2 -2
- 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 +2 -2
- 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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CountBuilder } from "
|
|
2
|
-
import { InsertBuilder } from "
|
|
3
|
-
import { SelectBuilder } from "
|
|
4
|
-
import { UpdateBuilder } from "
|
|
5
|
-
import { INTERNAL } from "
|
|
1
|
+
import { CountBuilder } from "../count/count-builder.js";
|
|
2
|
+
import { InsertBuilder } from "../insert/insert-builder.js";
|
|
3
|
+
import { SelectBuilder } from "../select/select-builder.js";
|
|
4
|
+
import { UpdateBuilder } from "../update/update-builder.js";
|
|
5
|
+
import { INTERNAL } from "../../core/helpers/methods.js";
|
|
6
|
+
import { RelqBuilderError } from "../../shared/errors/relq-errors.js";
|
|
6
7
|
export async function executeFindById(ctx, id, getPrimaryKeyColumn) {
|
|
7
8
|
const pkColumn = getPrimaryKeyColumn();
|
|
8
9
|
const dbColumn = ctx.relq[INTERNAL].transformToDbColumns(ctx.tableName, { [pkColumn]: id });
|
|
@@ -106,8 +107,7 @@ export async function executeCreateWith(ctx, parentData, related) {
|
|
|
106
107
|
const schema = internal.getSchema();
|
|
107
108
|
const relations = internal.getRelations();
|
|
108
109
|
if (!schema || !relations) {
|
|
109
|
-
throw new
|
|
110
|
-
'Use separate insert calls with a transaction instead.');
|
|
110
|
+
throw new RelqBuilderError('Cannot use createWith() without schema and relations config', { builder: 'createWith', hint: 'Pass schema and relations to your Relq client, or use separate insert calls with a transaction instead' });
|
|
111
111
|
}
|
|
112
112
|
const parentSchemaKey = findSchemaKeyByTableName(schema, ctx.tableName) || ctx.tableName;
|
|
113
113
|
try {
|
|
@@ -118,20 +118,19 @@ export async function executeCreateWith(ctx, parentData, related) {
|
|
|
118
118
|
const parentSQL = parentBuilder.toString();
|
|
119
119
|
const parentResult = await internal.executeQuery(parentSQL);
|
|
120
120
|
if (!parentResult.result.rows || parentResult.result.rows.length === 0) {
|
|
121
|
-
throw new
|
|
121
|
+
throw new RelqBuilderError('Parent insert returned no rows', { builder: 'createWith', hint: 'Ensure the parent table supports RETURNING * and the insert data is valid' });
|
|
122
122
|
}
|
|
123
123
|
const parentRow = parentResult.result.rows[0];
|
|
124
124
|
for (const [relationKey, childData] of Object.entries(related)) {
|
|
125
125
|
const childTableDef = schema[relationKey];
|
|
126
126
|
if (!childTableDef) {
|
|
127
|
-
throw new
|
|
127
|
+
throw new RelqBuilderError(`Unknown table "${relationKey}" in createWith()`, { builder: 'createWith', hint: 'Verify the relation key matches a table name defined in your schema' });
|
|
128
128
|
}
|
|
129
129
|
const childTableName = childTableDef.$name || relationKey;
|
|
130
|
-
const { resolveForeignKey } = await import("
|
|
130
|
+
const { resolveForeignKey } = await import("../utils/fk-resolver.js");
|
|
131
131
|
const fk = resolveForeignKey(relations, schema, parentSchemaKey, relationKey);
|
|
132
132
|
if (!fk) {
|
|
133
|
-
throw new
|
|
134
|
-
'Define the relationship in your relations config.');
|
|
133
|
+
throw new RelqBuilderError(`No FK relationship between "${parentSchemaKey}" and "${relationKey}"`, { builder: 'createWith', hint: 'Define the relationship in your relations config, or use separate insert calls with explicit FK values' });
|
|
135
134
|
}
|
|
136
135
|
let fkColumn;
|
|
137
136
|
let fkValue;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createTableProxy } from "
|
|
2
|
-
import { JoinConditionBuilder } from "
|
|
3
|
-
import { JOIN_INTERNAL, JOIN_SETUP } from "
|
|
4
|
-
import { JoinManyConditionBuilder } from "
|
|
5
|
-
import {
|
|
6
|
-
import { resolveForeignKey } from "
|
|
7
|
-
import { INTERNAL } from "
|
|
1
|
+
import { createTableProxy } from "../select/table-proxy.js";
|
|
2
|
+
import { JoinConditionBuilder } from "../select/join-condition-builder.js";
|
|
3
|
+
import { JOIN_INTERNAL, JOIN_SETUP } from "../select/join-internals.js";
|
|
4
|
+
import { JoinManyConditionBuilder } from "../select/join-many-condition-builder.js";
|
|
5
|
+
import { RelqBuilderError } from "../../shared/errors/relq-errors.js";
|
|
6
|
+
import { resolveForeignKey } from "../utils/fk-resolver.js";
|
|
7
|
+
import { INTERNAL } from "../../core/helpers/methods.js";
|
|
8
8
|
export function executeTypeSafeJoin(ctx, joinType, tableOrAlias, callback) {
|
|
9
9
|
const [rightTableKey, rightAlias] = Array.isArray(tableOrAlias)
|
|
10
10
|
? tableOrAlias
|
|
@@ -37,8 +37,8 @@ export function executeTypeSafeJoin(ctx, joinType, tableOrAlias, callback) {
|
|
|
37
37
|
conditionBuilder.equal(leftCol, rightCol);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
throw new
|
|
41
|
-
`Either provide a callback with explicit join conditions, or define the relationship in your relations config.`, { hint: `Use .join('${rightTableKey}', (on, ${rightTableKey}, source) => on.equal(${rightTableKey}.
|
|
40
|
+
throw new RelqBuilderError(`No foreign key relationship found between "${ctx.schemaKey || ctx.tableName}" and "${rightTableKey}". ` +
|
|
41
|
+
`Either provide a callback with explicit join conditions, or define the relationship in your relations config.`, { builder: 'join', hint: `Use .join('${rightTableKey}', (on, ${rightTableKey}, source) => on.equal(${rightTableKey}.fkColumn, source.id))` });
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
const selectedProps = conditionInternals.getSelectedColumns();
|
|
@@ -61,6 +61,7 @@ export function executeTypeSafeJoin(ctx, joinType, tableOrAlias, callback) {
|
|
|
61
61
|
sqlName: colDef.$columnName || toSnake(propName),
|
|
62
62
|
}));
|
|
63
63
|
}
|
|
64
|
+
const flatConfig = conditionInternals.getFlatConfig();
|
|
64
65
|
const joinClause = {
|
|
65
66
|
type: joinType,
|
|
66
67
|
table: rightTableName,
|
|
@@ -68,7 +69,11 @@ export function executeTypeSafeJoin(ctx, joinType, tableOrAlias, callback) {
|
|
|
68
69
|
schemaKey: rightTableKey,
|
|
69
70
|
onClause: conditionInternals.toSQL() || undefined,
|
|
70
71
|
usingColumns: conditionInternals.getUsingColumns() || undefined,
|
|
71
|
-
selectColumns
|
|
72
|
+
selectColumns,
|
|
73
|
+
flat: flatConfig ? {
|
|
74
|
+
mode: 'prefix',
|
|
75
|
+
prefix: flatConfig.prefix || rightAlias,
|
|
76
|
+
} : undefined,
|
|
72
77
|
};
|
|
73
78
|
ctx.builder.addStructuredJoin(joinClause);
|
|
74
79
|
}
|
|
@@ -167,22 +172,20 @@ export function executeTypeSafeJoinManyThrough(ctx, joinType, targetTableOrAlias
|
|
|
167
172
|
const schema = internal.getSchema();
|
|
168
173
|
const relations = internal.getRelations();
|
|
169
174
|
if (!schema || !relations) {
|
|
170
|
-
throw new
|
|
175
|
+
throw new RelqBuilderError(`Cannot use { through } without schema and relations config. Pass relations when creating Relq: new Relq(schema, dialect, { relations }).`, { builder: 'joinMany', hint: `Use the callback form of joinMany instead, or add relations to your Relq config.` });
|
|
171
176
|
}
|
|
172
|
-
const leftTableDef = internal.getTableDef(ctx.schemaKey || ctx.tableName);
|
|
173
177
|
const junctionTableDef = internal.getTableDef(junctionTableKey);
|
|
174
178
|
const targetTableDef = internal.getTableDef(targetKey);
|
|
175
|
-
const leftTableName = leftTableDef?.$name || ctx.tableName;
|
|
176
179
|
const junctionTableName = junctionTableDef?.$name || junctionTableKey;
|
|
177
180
|
const targetTableName = targetTableDef?.$name || targetKey;
|
|
178
181
|
const leftAlias = ctx.builder.getTableIdentifier();
|
|
179
182
|
const leftToJunction = resolveForeignKey(relations, schema, ctx.schemaKey || ctx.tableName, junctionTableKey);
|
|
180
183
|
if (!leftToJunction) {
|
|
181
|
-
throw new
|
|
184
|
+
throw new RelqBuilderError(`No foreign key relationship found between "${ctx.schemaKey || ctx.tableName}" and junction table "${junctionTableKey}". Define the relationship in your relations config.`, { builder: 'joinMany', hint: `Add a relation from "${ctx.schemaKey || ctx.tableName}" to "${junctionTableKey}" in pgRelations(), or use the callback form of joinMany.` });
|
|
182
185
|
}
|
|
183
186
|
const junctionToTarget = resolveForeignKey(relations, schema, junctionTableKey, targetKey);
|
|
184
187
|
if (!junctionToTarget) {
|
|
185
|
-
throw new
|
|
188
|
+
throw new RelqBuilderError(`No foreign key relationship found between junction table "${junctionTableKey}" and target table "${targetKey}". Define the relationship in your relations config.`, { builder: 'joinMany', hint: `Add a relation from "${junctionTableKey}" to "${targetKey}" in pgRelations(), or use the callback form of joinMany.` });
|
|
186
189
|
}
|
|
187
190
|
const conditionBuilder = new JoinManyConditionBuilder();
|
|
188
191
|
if (callback) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Cursor from "../../addon/cursor.js";
|
|
2
2
|
import { RelqConfigError, RelqQueryError } from "../../shared/errors/relq-errors.js";
|
|
3
3
|
import { randomLimit } from "../../types/pagination-types.js";
|
|
4
|
-
import { INTERNAL } from "
|
|
4
|
+
import { INTERNAL } from "../../core/helpers/methods.js";
|
|
5
5
|
export async function executeCursorEach(ctx, callback, options = {}) {
|
|
6
6
|
const batchSize = options.batchSize ?? 100;
|
|
7
7
|
const sql = ctx.builder.toString();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
2
|
function isColumnRef(value) {
|
|
3
3
|
return typeof value === 'object' && value !== null && value.__type === 'column_ref';
|
|
4
4
|
}
|
|
@@ -173,7 +173,7 @@ export class ConflictBuilder {
|
|
|
173
173
|
return this._tableName;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
export function buildConflictUpdateSql(updateData,
|
|
176
|
+
export function buildConflictUpdateSql(updateData, _tableName, columnResolver) {
|
|
177
177
|
const resolve = (col) => columnResolver ? columnResolver(col) : col;
|
|
178
178
|
const setClauses = [];
|
|
179
179
|
for (const [column, value] of Object.entries(updateData)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import format from "
|
|
2
|
-
import { convertCase } from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
|
+
import { convertCase } from "../../utils/case-converter.js";
|
|
3
3
|
import { SelectBuilder } from "../select/select-builder.js";
|
|
4
4
|
import { CountBuilder } from "../count/count-builder.js";
|
|
5
5
|
import { ConflictBuilder, buildConflictUpdateSql } from "./conflict-builder.js";
|
|
6
|
-
import { RelqBuilderError } from "
|
|
6
|
+
import { RelqBuilderError } from "../../shared/errors/relq-errors.js";
|
|
7
7
|
export class InsertBuilder {
|
|
8
8
|
tableName;
|
|
9
9
|
insertData;
|
|
@@ -76,8 +76,11 @@ export class InsertBuilder {
|
|
|
76
76
|
if (this.insertData.length === 0) {
|
|
77
77
|
this.originalColumns = Object.keys(normalizedRows[0]).sort();
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
this.validateColumns(
|
|
79
|
+
if (normalizedRows.length > 0) {
|
|
80
|
+
this.validateColumns(normalizedRows[0]);
|
|
81
|
+
if (normalizedRows.length > 1) {
|
|
82
|
+
this.validateColumns(normalizedRows[normalizedRows.length - 1]);
|
|
83
|
+
}
|
|
81
84
|
}
|
|
82
85
|
this.insertData.push(...normalizedRows);
|
|
83
86
|
return this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { Client } from "
|
|
3
|
-
import format from "
|
|
2
|
+
import { Client } from "../../addon/pg.js";
|
|
3
|
+
import format from "../../shared/pg-format.js";
|
|
4
4
|
export class ListenerConnection extends EventEmitter {
|
|
5
5
|
client = null;
|
|
6
6
|
config;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import format from "
|
|
2
|
-
import { RelqQueryError } from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
|
+
import { RelqQueryError } from "../../shared/errors/relq-errors.js";
|
|
3
3
|
export class RawQueryBuilder {
|
|
4
4
|
query;
|
|
5
5
|
params;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
2
|
export class SqlFragment {
|
|
3
3
|
text;
|
|
4
4
|
_isSqlFragment = true;
|
|
@@ -12,9 +12,6 @@ export class SqlFragment {
|
|
|
12
12
|
function sqlIdentifier(name) {
|
|
13
13
|
return new SqlFragment(format.ident(name));
|
|
14
14
|
}
|
|
15
|
-
function sqlRaw(text) {
|
|
16
|
-
return new SqlFragment(text);
|
|
17
|
-
}
|
|
18
15
|
function sql(strings, ...values) {
|
|
19
16
|
let result = '';
|
|
20
17
|
for (let i = 0; i < strings.length; i++) {
|
|
@@ -61,6 +58,4 @@ function formatValue(value) {
|
|
|
61
58
|
return format('%L', String(value));
|
|
62
59
|
}
|
|
63
60
|
sql.id = sqlIdentifier;
|
|
64
|
-
sql.raw = sqlRaw;
|
|
65
|
-
sql.fragment = sqlRaw;
|
|
66
61
|
export { sql };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
2
|
import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
|
|
3
3
|
const NUMERIC_FUNCS = new Set(['COUNT', 'SUM', 'AVG', 'MIN', 'MAX']);
|
|
4
4
|
export class AggregateQueryBuilder {
|
|
@@ -81,10 +81,15 @@ export class AggregateQueryBuilder {
|
|
|
81
81
|
this.entries.push({ func: 'BOOL_OR', column, alias: alias || column });
|
|
82
82
|
return this;
|
|
83
83
|
}
|
|
84
|
-
where(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
where(callbackOrCondition) {
|
|
85
|
+
if (callbackOrCondition instanceof ConditionCollector) {
|
|
86
|
+
this.whereConditions.push(...callbackOrCondition.getConditions());
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const collector = new ConditionCollector();
|
|
90
|
+
callbackOrCondition(collector);
|
|
91
|
+
this.whereConditions.push(...collector.getConditions());
|
|
92
|
+
}
|
|
88
93
|
return this;
|
|
89
94
|
}
|
|
90
95
|
having(callback) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JoinConditionBuilder } from "./join-condition-builder.js";
|
|
2
2
|
import { columnRefToSQL, columnRefToSQLUnqualified } from "./table-proxy.js";
|
|
3
3
|
import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
|
|
4
|
-
import format from "
|
|
4
|
+
import format from "../../shared/pg-format.js";
|
|
5
5
|
export class JoinManyBuilder extends JoinConditionBuilder {
|
|
6
6
|
orderBySpecs = [];
|
|
7
7
|
selectColumns = [];
|
|
@@ -120,7 +120,7 @@ export class JoinManyBuilder extends JoinConditionBuilder {
|
|
|
120
120
|
.map(col => columnRefToSQLUnqualified(col))
|
|
121
121
|
.join(', ');
|
|
122
122
|
}
|
|
123
|
-
buildWherePart(
|
|
123
|
+
buildWherePart(_leftAlias) {
|
|
124
124
|
const parts = [];
|
|
125
125
|
for (const cond of this.conditions) {
|
|
126
126
|
if (cond.type === 'using' || cond.type === 'raw') {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { columnRefToSQL, isColumnRef } from "./table-proxy.js";
|
|
2
2
|
import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
|
|
3
|
-
import format from "
|
|
3
|
+
import format from "../../shared/pg-format.js";
|
|
4
4
|
import { JOIN_INTERNAL } from "./join-internals.js";
|
|
5
5
|
export class JoinConditionBuilder {
|
|
6
6
|
conditions = [];
|
|
7
7
|
whereConditions = [];
|
|
8
8
|
selectedColumns;
|
|
9
|
+
flatConfig;
|
|
9
10
|
equal(left, right) {
|
|
10
11
|
this.conditions.push({
|
|
11
12
|
type: 'equal',
|
|
@@ -100,6 +101,14 @@ export class JoinConditionBuilder {
|
|
|
100
101
|
}
|
|
101
102
|
return this;
|
|
102
103
|
}
|
|
104
|
+
flat() {
|
|
105
|
+
if (!this.selectedColumns || this.selectedColumns.length === 0) {
|
|
106
|
+
throw new Error('Relq: .flat() requires .select() with explicit columns. ' +
|
|
107
|
+
'Cannot flatten without knowing the column set.');
|
|
108
|
+
}
|
|
109
|
+
this.flatConfig = { mode: 'prefix' };
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
103
112
|
get [JOIN_INTERNAL]() {
|
|
104
113
|
return {
|
|
105
114
|
toSQL: () => this.internalToSQL(),
|
|
@@ -111,6 +120,7 @@ export class JoinConditionBuilder {
|
|
|
111
120
|
hasConditions: () => this.conditions.length > 0,
|
|
112
121
|
hasWhereConditions: () => this.whereConditions.length > 0,
|
|
113
122
|
getSelectedColumns: () => this.selectedColumns ?? null,
|
|
123
|
+
getFlatConfig: () => this.flatConfig ?? null,
|
|
114
124
|
};
|
|
115
125
|
}
|
|
116
126
|
internalToSQL() {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { columnRefToSQL } from "./table-proxy.js";
|
|
2
2
|
import { JoinConditionBuilder } from "./join-condition-builder.js";
|
|
3
3
|
import { JOIN_INTERNAL, JOIN_SETUP } from "./join-internals.js";
|
|
4
|
-
import format from "
|
|
4
|
+
import format from "../../shared/pg-format.js";
|
|
5
5
|
export class JoinManyConditionBuilder extends JoinConditionBuilder {
|
|
6
6
|
orderSpecs = [];
|
|
7
7
|
limitValue;
|
|
8
8
|
offsetValue;
|
|
9
9
|
innerJoins = [];
|
|
10
10
|
proxyCreator;
|
|
11
|
-
rightProxy;
|
|
12
11
|
orderBy(column, direction = 'ASC', nulls) {
|
|
13
12
|
this.orderSpecs.push({ column, direction, nulls });
|
|
14
13
|
return this;
|
|
@@ -22,9 +21,8 @@ export class JoinManyConditionBuilder extends JoinConditionBuilder {
|
|
|
22
21
|
return this;
|
|
23
22
|
}
|
|
24
23
|
get [JOIN_SETUP]() {
|
|
25
|
-
return (creator,
|
|
24
|
+
return (creator, _rightProxy) => {
|
|
26
25
|
this.proxyCreator = creator;
|
|
27
|
-
this.rightProxy = rightProxy;
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
innerJoin(tableOrAlias, callback) {
|
|
@@ -85,6 +83,7 @@ export class JoinManyConditionBuilder extends JoinConditionBuilder {
|
|
|
85
83
|
hasConditions: () => this.conditions.length > 0,
|
|
86
84
|
hasWhereConditions: () => this.whereConditions.length > 0,
|
|
87
85
|
getSelectedColumns: () => this.selectedColumns ?? null,
|
|
86
|
+
getFlatConfig: () => this.flatConfig ?? null,
|
|
88
87
|
toSelectSQL: (alias) => this.buildSelectSQL(alias),
|
|
89
88
|
toOrderBySQL: () => this.buildOrderBySQL(),
|
|
90
89
|
toLimitSQL: () => this.buildLimitSQL(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
2
|
import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
|
|
3
3
|
class ScalarResultImpl {
|
|
4
4
|
sql;
|
|
@@ -66,6 +66,36 @@ export class ScalarQueryBuilderImpl {
|
|
|
66
66
|
const sql = `(EXISTS(SELECT 1 FROM ${format.ident(this.tableName)}${whereClause}))`;
|
|
67
67
|
return new ScalarResultImpl(sql);
|
|
68
68
|
}
|
|
69
|
+
countDistinct(column) {
|
|
70
|
+
const sqlColumn = this.resolveColumn(column);
|
|
71
|
+
const sql = this.buildSQL(`COUNT(DISTINCT ${format.ident(sqlColumn)})`);
|
|
72
|
+
return new ScalarResultImpl(sql);
|
|
73
|
+
}
|
|
74
|
+
stringAgg(column, delimiter = ', ') {
|
|
75
|
+
const sqlColumn = this.resolveColumn(column);
|
|
76
|
+
const sql = this.buildSQL(`STRING_AGG(${format.ident(sqlColumn)}::text, ${format.literal(delimiter)})`);
|
|
77
|
+
return new ScalarResultImpl(sql);
|
|
78
|
+
}
|
|
79
|
+
arrayAgg(column) {
|
|
80
|
+
const sqlColumn = this.resolveColumn(column);
|
|
81
|
+
const sql = this.buildSQL(`COALESCE(ARRAY_AGG(${format.ident(sqlColumn)}), ARRAY[]::text[])`);
|
|
82
|
+
return new ScalarResultImpl(sql);
|
|
83
|
+
}
|
|
84
|
+
jsonAgg(column) {
|
|
85
|
+
const sqlColumn = this.resolveColumn(column);
|
|
86
|
+
const sql = this.buildSQL(`COALESCE(JSON_AGG(${format.ident(sqlColumn)}), '[]'::json)`);
|
|
87
|
+
return new ScalarResultImpl(sql);
|
|
88
|
+
}
|
|
89
|
+
boolAnd(column) {
|
|
90
|
+
const sqlColumn = this.resolveColumn(column);
|
|
91
|
+
const sql = this.buildSQL(`BOOL_AND(${format.ident(sqlColumn)})`);
|
|
92
|
+
return new ScalarResultImpl(sql);
|
|
93
|
+
}
|
|
94
|
+
boolOr(column) {
|
|
95
|
+
const sqlColumn = this.resolveColumn(column);
|
|
96
|
+
const sql = this.buildSQL(`BOOL_OR(${format.ident(sqlColumn)})`);
|
|
97
|
+
return new ScalarResultImpl(sql);
|
|
98
|
+
}
|
|
69
99
|
resolveColumn(column) {
|
|
70
100
|
if (this.columnResolver) {
|
|
71
101
|
return this.columnResolver(column);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
2
|
import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
|
|
3
3
|
export class SelectBuilder {
|
|
4
4
|
tableName;
|
|
@@ -69,10 +69,15 @@ export class SelectBuilder {
|
|
|
69
69
|
this.isDistinct = true;
|
|
70
70
|
return this;
|
|
71
71
|
}
|
|
72
|
-
where(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
where(callbackOrCondition) {
|
|
73
|
+
if (callbackOrCondition instanceof ConditionCollector) {
|
|
74
|
+
this.whereConditions.push(...callbackOrCondition.getConditions());
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const conditionBuilder = new ConditionCollector();
|
|
78
|
+
callbackOrCondition(conditionBuilder);
|
|
79
|
+
this.whereConditions.push(...conditionBuilder.getConditions());
|
|
80
|
+
}
|
|
76
81
|
return this;
|
|
77
82
|
}
|
|
78
83
|
join(table, condition) {
|
|
@@ -271,10 +276,32 @@ export class SelectBuilder {
|
|
|
271
276
|
}
|
|
272
277
|
return format.ident(col);
|
|
273
278
|
});
|
|
279
|
+
const hasGroupBy = this.groupByColumns.length > 0
|
|
280
|
+
|| (this.includeExpressions.length > 0 && this.selectColumns.some(c => typeof c === 'string' && c !== '*'));
|
|
274
281
|
for (const join of this.structuredJoins) {
|
|
275
282
|
if (join.type === 'LEFT JOIN LATERAL' || join.type === 'JOIN LATERAL') {
|
|
276
283
|
columns.push(`${format.ident(join.alias + '_lateral')}.${format.ident(join.alias)} AS ${format.ident(join.alias)}`);
|
|
277
284
|
}
|
|
285
|
+
else if (hasGroupBy) {
|
|
286
|
+
if (join.selectColumns && join.selectColumns.length > 0) {
|
|
287
|
+
const jsonArgs = join.selectColumns
|
|
288
|
+
.map(col => `'${col.property}', ${format.ident(join.alias)}.${format.ident(col.sqlName)}`)
|
|
289
|
+
.join(', ');
|
|
290
|
+
columns.push(`COALESCE(json_agg(json_build_object(${jsonArgs})) FILTER (WHERE ${format.ident(join.alias)}.${format.ident(join.selectColumns[0].sqlName)} IS NOT NULL), '[]'::json) AS ${format.ident(join.alias)}`);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
columns.push(`COALESCE(json_agg(row_to_json(${format.ident(join.alias)}.*)) FILTER (WHERE ${format.ident(join.alias)} IS NOT NULL), '[]'::json) AS ${format.ident(join.alias)}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else if (join.flat && join.selectColumns && join.selectColumns.length > 0) {
|
|
297
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
298
|
+
const prefix = join.flat.prefix || join.alias;
|
|
299
|
+
for (const col of join.selectColumns) {
|
|
300
|
+
const sqlRef = `${format.ident(join.alias)}.${format.ident(col.sqlName)}`;
|
|
301
|
+
const alias = `${prefix}${capitalize(col.property)}`;
|
|
302
|
+
columns.push(`${sqlRef} AS ${format.ident(alias)}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
278
305
|
else if (join.selectColumns && join.selectColumns.length > 0) {
|
|
279
306
|
const jsonArgs = join.selectColumns
|
|
280
307
|
.map(col => `'${col.property}', ${format.ident(join.alias)}.${format.ident(col.sqlName)}`)
|
|
@@ -319,8 +346,14 @@ export class SelectBuilder {
|
|
|
319
346
|
}
|
|
320
347
|
query += ' WHERE ' + buildConditionsSQL(conditions);
|
|
321
348
|
}
|
|
322
|
-
|
|
323
|
-
|
|
349
|
+
let effectiveGroupBy = this.groupByColumns;
|
|
350
|
+
if (effectiveGroupBy.length === 0 && this.includeExpressions.length > 0) {
|
|
351
|
+
effectiveGroupBy = this.selectColumns
|
|
352
|
+
.filter(col => typeof col === 'string' && col !== '*')
|
|
353
|
+
.map(col => col);
|
|
354
|
+
}
|
|
355
|
+
if (effectiveGroupBy.length > 0) {
|
|
356
|
+
const groupBySQL = effectiveGroupBy.map(col => {
|
|
324
357
|
if (col.includes('.'))
|
|
325
358
|
return col;
|
|
326
359
|
if (hasJoins)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { columnRefToSQL } from "./table-proxy.js";
|
|
2
|
+
export class SqlExpression {
|
|
3
|
+
sql;
|
|
4
|
+
_isSqlExpression = true;
|
|
5
|
+
constructor(sql) {
|
|
6
|
+
this.sql = sql;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class AggregateFunctions {
|
|
10
|
+
count(ref) {
|
|
11
|
+
if (!ref)
|
|
12
|
+
return new SqlExpression('COALESCE(COUNT(*)::integer, 0)');
|
|
13
|
+
return new SqlExpression(`COALESCE(COUNT(${columnRefToSQL(ref)})::integer, 0)`);
|
|
14
|
+
}
|
|
15
|
+
countDistinct(ref) {
|
|
16
|
+
return new SqlExpression(`COALESCE(COUNT(DISTINCT ${columnRefToSQL(ref)})::integer, 0)`);
|
|
17
|
+
}
|
|
18
|
+
sum(ref) {
|
|
19
|
+
return new SqlExpression(`COALESCE(SUM(${columnRefToSQL(ref)})::float, 0)`);
|
|
20
|
+
}
|
|
21
|
+
avg(ref) {
|
|
22
|
+
return new SqlExpression(`AVG(${columnRefToSQL(ref)})::float`);
|
|
23
|
+
}
|
|
24
|
+
min(ref) {
|
|
25
|
+
return new SqlExpression(`MIN(${columnRefToSQL(ref)})`);
|
|
26
|
+
}
|
|
27
|
+
max(ref) {
|
|
28
|
+
return new SqlExpression(`MAX(${columnRefToSQL(ref)})`);
|
|
29
|
+
}
|
|
30
|
+
stringAgg(ref, delimiter = ', ') {
|
|
31
|
+
return new SqlExpression(`COALESCE(STRING_AGG(${columnRefToSQL(ref)}::text, '${delimiter}'), '')`);
|
|
32
|
+
}
|
|
33
|
+
arrayAgg(ref) {
|
|
34
|
+
return new SqlExpression(`COALESCE(ARRAY_AGG(${columnRefToSQL(ref)}) FILTER (WHERE ${columnRefToSQL(ref)} IS NOT NULL), '{}')`);
|
|
35
|
+
}
|
|
36
|
+
arrayAggDistinct(ref) {
|
|
37
|
+
return new SqlExpression(`COALESCE(ARRAY_AGG(DISTINCT ${columnRefToSQL(ref)}) FILTER (WHERE ${columnRefToSQL(ref)} IS NOT NULL), '{}')`);
|
|
38
|
+
}
|
|
39
|
+
boolAnd(ref) {
|
|
40
|
+
return new SqlExpression(`COALESCE(BOOL_AND(${columnRefToSQL(ref)}), false)`);
|
|
41
|
+
}
|
|
42
|
+
boolOr(ref) {
|
|
43
|
+
return new SqlExpression(`COALESCE(BOOL_OR(${columnRefToSQL(ref)}), false)`);
|
|
44
|
+
}
|
|
45
|
+
stddev(ref) {
|
|
46
|
+
return new SqlExpression(`STDDEV(${columnRefToSQL(ref)})::float`);
|
|
47
|
+
}
|
|
48
|
+
variance(ref) {
|
|
49
|
+
return new SqlExpression(`VARIANCE(${columnRefToSQL(ref)})::float`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from "
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
2
|
export class ArrayStringUpdateBuilder {
|
|
3
3
|
set(values) {
|
|
4
4
|
if (values.length === 0)
|
|
@@ -188,10 +188,7 @@ export class ArrayJsonbUpdateBuilder {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
export class ArrayUpdateBuilder {
|
|
191
|
-
|
|
192
|
-
constructor(currentColumn) {
|
|
193
|
-
this.currentColumn = currentColumn;
|
|
194
|
-
}
|
|
191
|
+
constructor(_currentColumn) { }
|
|
195
192
|
get string() {
|
|
196
193
|
return new ArrayStringUpdateBuilder();
|
|
197
194
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import format from "../../shared/pg-format.js";
|
|
2
|
+
export class ColumnExpressionBuilder {
|
|
3
|
+
increment(amount = 1) {
|
|
4
|
+
return `COALESCE(__COLUMN__, 0) + ${format.literal(amount)}`;
|
|
5
|
+
}
|
|
6
|
+
decrement(amount = 1) {
|
|
7
|
+
return `COALESCE(__COLUMN__, 0) - ${format.literal(amount)}`;
|
|
8
|
+
}
|
|
9
|
+
multiply(factor) {
|
|
10
|
+
return `COALESCE(__COLUMN__, 0) * ${format.literal(factor)}`;
|
|
11
|
+
}
|
|
12
|
+
toggle() {
|
|
13
|
+
return `NOT COALESCE(__COLUMN__, false)`;
|
|
14
|
+
}
|
|
15
|
+
concat(suffix) {
|
|
16
|
+
return `COALESCE(__COLUMN__, '') || ${format.literal(suffix)}`;
|
|
17
|
+
}
|
|
18
|
+
prepend(prefix) {
|
|
19
|
+
return `${format.literal(prefix)} || COALESCE(__COLUMN__, '')`;
|
|
20
|
+
}
|
|
21
|
+
replace(search, replacement) {
|
|
22
|
+
return `REPLACE(COALESCE(__COLUMN__, ''), ${format.literal(search)}, ${format.literal(replacement)})`;
|
|
23
|
+
}
|
|
24
|
+
lower() {
|
|
25
|
+
return `LOWER(__COLUMN__)`;
|
|
26
|
+
}
|
|
27
|
+
upper() {
|
|
28
|
+
return `UPPER(__COLUMN__)`;
|
|
29
|
+
}
|
|
30
|
+
trim() {
|
|
31
|
+
return `TRIM(__COLUMN__)`;
|
|
32
|
+
}
|
|
33
|
+
now() {
|
|
34
|
+
return `NOW()`;
|
|
35
|
+
}
|
|
36
|
+
addInterval(value, unit) {
|
|
37
|
+
return `COALESCE(__COLUMN__, NOW()) + INTERVAL '${value} ${unit}'`;
|
|
38
|
+
}
|
|
39
|
+
subtractInterval(value, unit) {
|
|
40
|
+
return `COALESCE(__COLUMN__, NOW()) - INTERVAL '${value} ${unit}'`;
|
|
41
|
+
}
|
|
42
|
+
}
|