@relq/orm 0.1.3 → 0.1.5
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 +2 -1407
- package/dist/cjs/addon/mysql2.cjs +21143 -0
- package/dist/cjs/addon/pg.cjs +5 -5
- 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 +59 -41
- 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 +1 -1438
- package/dist/esm/addon/mysql2.js +21129 -0
- package/dist/esm/addon/pg.js +5 -5
- 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 +54 -32
- 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 +6 -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
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import mysqlFormat from "../clients/shared/mysql-format.js";
|
|
2
|
+
import { MysqlConditionCollector, buildMysqlConditionsSQL } from "../condition/condition-collector.js";
|
|
3
|
+
const NUMERIC_FUNCS = new Set(['COUNT', 'SUM', 'AVG', 'MIN', 'MAX']);
|
|
4
|
+
export class MysqlAggregateQueryBuilder {
|
|
5
|
+
tableName;
|
|
6
|
+
groupByColumns = [];
|
|
7
|
+
entries = [];
|
|
8
|
+
whereConditions = [];
|
|
9
|
+
havingConditions = [];
|
|
10
|
+
orderByColumns = [];
|
|
11
|
+
limitValue;
|
|
12
|
+
offsetValue;
|
|
13
|
+
constructor(tableName) {
|
|
14
|
+
this.tableName = tableName;
|
|
15
|
+
}
|
|
16
|
+
groupBy(...columns) {
|
|
17
|
+
this.groupByColumns.push(...columns);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
count(alias = 'count') {
|
|
21
|
+
this.entries.push({ func: 'COUNT', column: '*', alias });
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
countColumn(column, alias) {
|
|
25
|
+
this.entries.push({ func: 'COUNT', column, alias: alias || column });
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
countDistinct(column, alias) {
|
|
29
|
+
this.entries.push({ func: 'COUNT', column, alias: alias || column, distinct: true });
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
sum(column, alias, filter) {
|
|
33
|
+
const entry = { func: 'SUM', column, alias: alias || column };
|
|
34
|
+
if (filter) {
|
|
35
|
+
const collector = new MysqlConditionCollector();
|
|
36
|
+
filter(collector);
|
|
37
|
+
entry.filterConditions = collector.getConditions();
|
|
38
|
+
}
|
|
39
|
+
this.entries.push(entry);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
avg(column, alias, filter) {
|
|
43
|
+
const entry = { func: 'AVG', column, alias: alias || column };
|
|
44
|
+
if (filter) {
|
|
45
|
+
const collector = new MysqlConditionCollector();
|
|
46
|
+
filter(collector);
|
|
47
|
+
entry.filterConditions = collector.getConditions();
|
|
48
|
+
}
|
|
49
|
+
this.entries.push(entry);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
min(column, alias) {
|
|
53
|
+
this.entries.push({ func: 'MIN', column, alias: alias || column });
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
max(column, alias) {
|
|
57
|
+
this.entries.push({ func: 'MAX', column, alias: alias || column });
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
groupConcat(column, separator = ', ', alias, orderBy, orderDir = 'ASC') {
|
|
61
|
+
const entry = {
|
|
62
|
+
func: 'GROUP_CONCAT',
|
|
63
|
+
column,
|
|
64
|
+
alias: alias || column,
|
|
65
|
+
separator,
|
|
66
|
+
};
|
|
67
|
+
if (orderBy) {
|
|
68
|
+
entry.orderByColumn = orderBy;
|
|
69
|
+
entry.orderByDirection = orderDir;
|
|
70
|
+
}
|
|
71
|
+
this.entries.push(entry);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
jsonArrayAgg(column, alias) {
|
|
75
|
+
this.entries.push({ func: 'JSON_ARRAYAGG', column, alias: alias || column });
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
bitAnd(column, alias) {
|
|
79
|
+
this.entries.push({ func: 'BIT_AND', column, alias: alias || column });
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
bitOr(column, alias) {
|
|
83
|
+
this.entries.push({ func: 'BIT_OR', column, alias: alias || column });
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
where(callbackOrCondition) {
|
|
87
|
+
if (callbackOrCondition instanceof MysqlConditionCollector) {
|
|
88
|
+
this.whereConditions.push(...callbackOrCondition.getConditions());
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const collector = new MysqlConditionCollector();
|
|
92
|
+
callbackOrCondition(collector);
|
|
93
|
+
this.whereConditions.push(...collector.getConditions());
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
having(callback) {
|
|
98
|
+
const collector = new MysqlConditionCollector();
|
|
99
|
+
callback(collector);
|
|
100
|
+
this.havingConditions.push(...collector.getConditions());
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
orderBy(column, direction = 'ASC') {
|
|
104
|
+
this.orderByColumns.push({ column, direction });
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
limit(count) {
|
|
108
|
+
this.limitValue = count;
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
offset(count) {
|
|
112
|
+
this.offsetValue = count;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
getNumericAliases() {
|
|
116
|
+
return this.entries
|
|
117
|
+
.filter(e => NUMERIC_FUNCS.has(e.func))
|
|
118
|
+
.map(e => e.alias);
|
|
119
|
+
}
|
|
120
|
+
getGroupByColumns() {
|
|
121
|
+
return this.groupByColumns;
|
|
122
|
+
}
|
|
123
|
+
toString() {
|
|
124
|
+
const selectParts = [];
|
|
125
|
+
for (const col of this.groupByColumns) {
|
|
126
|
+
selectParts.push(mysqlFormat.ident(col));
|
|
127
|
+
}
|
|
128
|
+
for (const entry of this.entries) {
|
|
129
|
+
selectParts.push(this.buildEntrySQL(entry));
|
|
130
|
+
}
|
|
131
|
+
if (selectParts.length === 0) {
|
|
132
|
+
selectParts.push('COUNT(*) AS `count`');
|
|
133
|
+
}
|
|
134
|
+
let query = `SELECT ${selectParts.join(', ')} FROM ${mysqlFormat.ident(this.tableName)}`;
|
|
135
|
+
if (this.whereConditions.length > 0) {
|
|
136
|
+
query += ' WHERE ' + buildMysqlConditionsSQL(this.whereConditions);
|
|
137
|
+
}
|
|
138
|
+
if (this.groupByColumns.length > 0) {
|
|
139
|
+
query += ' GROUP BY ' + this.groupByColumns.map(col => mysqlFormat.ident(col)).join(', ');
|
|
140
|
+
}
|
|
141
|
+
if (this.havingConditions.length > 0) {
|
|
142
|
+
query += ' HAVING ' + buildMysqlConditionsSQL(this.havingConditions);
|
|
143
|
+
}
|
|
144
|
+
if (this.orderByColumns.length > 0) {
|
|
145
|
+
query += ' ORDER BY ' + this.orderByColumns
|
|
146
|
+
.map(o => `${mysqlFormat.ident(o.column)} ${o.direction}`)
|
|
147
|
+
.join(', ');
|
|
148
|
+
}
|
|
149
|
+
if (this.limitValue !== undefined) {
|
|
150
|
+
query += ` LIMIT ${this.limitValue}`;
|
|
151
|
+
}
|
|
152
|
+
if (this.offsetValue !== undefined) {
|
|
153
|
+
query += ` OFFSET ${this.offsetValue}`;
|
|
154
|
+
}
|
|
155
|
+
return query;
|
|
156
|
+
}
|
|
157
|
+
buildEntrySQL(entry) {
|
|
158
|
+
let columnExpr;
|
|
159
|
+
if (entry.column === '*') {
|
|
160
|
+
columnExpr = '*';
|
|
161
|
+
}
|
|
162
|
+
else if (entry.distinct) {
|
|
163
|
+
columnExpr = `DISTINCT ${mysqlFormat.ident(entry.column)}`;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
columnExpr = mysqlFormat.ident(entry.column);
|
|
167
|
+
}
|
|
168
|
+
if (entry.filterConditions && entry.filterConditions.length > 0) {
|
|
169
|
+
const filterSQL = buildMysqlConditionsSQL(entry.filterConditions);
|
|
170
|
+
return this.buildFilteredAggregateSQL(entry.func, columnExpr, filterSQL, entry.alias);
|
|
171
|
+
}
|
|
172
|
+
if (entry.func === 'GROUP_CONCAT') {
|
|
173
|
+
return this.buildGroupConcatSQL(entry);
|
|
174
|
+
}
|
|
175
|
+
let sql = `${entry.func}(${columnExpr})`;
|
|
176
|
+
sql += ` AS ${mysqlFormat.ident(entry.alias)}`;
|
|
177
|
+
return sql;
|
|
178
|
+
}
|
|
179
|
+
buildGroupConcatSQL(entry) {
|
|
180
|
+
let inner = entry.distinct
|
|
181
|
+
? `DISTINCT ${mysqlFormat.ident(entry.column)}`
|
|
182
|
+
: mysqlFormat.ident(entry.column);
|
|
183
|
+
if (entry.orderByColumn) {
|
|
184
|
+
inner += ` ORDER BY ${mysqlFormat.ident(entry.orderByColumn)} ${entry.orderByDirection || 'ASC'}`;
|
|
185
|
+
}
|
|
186
|
+
if (entry.separator !== undefined) {
|
|
187
|
+
inner += ` SEPARATOR ${mysqlFormat.literal(entry.separator)}`;
|
|
188
|
+
}
|
|
189
|
+
return `GROUP_CONCAT(${inner}) AS ${mysqlFormat.ident(entry.alias)}`;
|
|
190
|
+
}
|
|
191
|
+
buildFilteredAggregateSQL(func, columnExpr, filterSQL, alias) {
|
|
192
|
+
let caseExpr;
|
|
193
|
+
if (func === 'COUNT') {
|
|
194
|
+
caseExpr = `SUM(CASE WHEN ${filterSQL} THEN 1 ELSE 0 END)`;
|
|
195
|
+
}
|
|
196
|
+
else if (func === 'AVG' || func === 'MIN' || func === 'MAX') {
|
|
197
|
+
caseExpr = `${func}(CASE WHEN ${filterSQL} THEN ${columnExpr} ELSE NULL END)`;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
caseExpr = `${func}(CASE WHEN ${filterSQL} THEN ${columnExpr} ELSE 0 END)`;
|
|
201
|
+
}
|
|
202
|
+
return `${caseExpr} AS ${mysqlFormat.ident(alias)}`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { MysqlSelectBuilder } from "./select-builder.js";
|
|
2
|
+
export { MYSQL_JOIN_INTERNAL, MYSQL_JOIN_SETUP } from "./join-internals.js";
|
|
3
|
+
export { createMysqlTableProxy, createMysqlJoinCallbackParams, mysqlColumnRefToSQL, mysqlColumnRefToSQLUnqualified, mysqlColumnRefsEqual, isMysqlColumnRef } from "./table-proxy.js";
|
|
4
|
+
export { MysqlSqlExpression, MysqlAggregateFunctions } from "./sql-expression.js";
|
|
5
|
+
export { MysqlJoinConditionBuilder, createMysqlJoinConditionBuilder } from "./join-condition-builder.js";
|
|
6
|
+
export { MysqlJoinManyBuilder, createMysqlJoinManyBuilder } from "./join-builder.js";
|
|
7
|
+
export { MysqlAggregateQueryBuilder } from "./aggregate-builder.js";
|
|
8
|
+
export { MysqlScalarQueryBuilderImpl, createMysqlScalarTableAccessor } from "./scalar-query-builder.js";
|
|
9
|
+
export { MysqlScalarSelectBuilder, MysqlConnectedScalarSelectBuilder } from "./scalar-select-builder.js";
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { MysqlJoinConditionBuilder } from "./join-condition-builder.js";
|
|
2
|
+
import { mysqlColumnRefToSQL, mysqlColumnRefToSQLUnqualified } from "./table-proxy.js";
|
|
3
|
+
import { MysqlConditionCollector, buildMysqlConditionsSQL } from "../condition/condition-collector.js";
|
|
4
|
+
import mysqlFormat from "../clients/shared/mysql-format.js";
|
|
5
|
+
export class MysqlJoinManyBuilder extends MysqlJoinConditionBuilder {
|
|
6
|
+
orderBySpecs = [];
|
|
7
|
+
selectColumns = [];
|
|
8
|
+
limitValue;
|
|
9
|
+
offsetValue;
|
|
10
|
+
groupByColumns = [];
|
|
11
|
+
havingConditions = [];
|
|
12
|
+
selectRefs(columns) {
|
|
13
|
+
this.selectColumns = columns;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
orderBy(column, direction = 'ASC') {
|
|
17
|
+
this.orderBySpecs.push({ column, direction });
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
limit(count) {
|
|
21
|
+
this.limitValue = count;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
offset(count) {
|
|
25
|
+
this.offsetValue = count;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
groupBy(...columns) {
|
|
29
|
+
this.groupByColumns.push(...columns);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
having(callback) {
|
|
33
|
+
const collector = new MysqlConditionCollector();
|
|
34
|
+
callback(collector);
|
|
35
|
+
this.havingConditions.push(...collector.getConditions());
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
hasQueryModifiers() {
|
|
39
|
+
return (this.orderBySpecs.length > 0 ||
|
|
40
|
+
this.selectColumns.length > 0 ||
|
|
41
|
+
this.limitValue !== undefined ||
|
|
42
|
+
this.offsetValue !== undefined ||
|
|
43
|
+
this.groupByColumns.length > 0 ||
|
|
44
|
+
this.havingConditions.length > 0);
|
|
45
|
+
}
|
|
46
|
+
getSelectColumns() {
|
|
47
|
+
return [...this.selectColumns];
|
|
48
|
+
}
|
|
49
|
+
getOrderBySpecs() {
|
|
50
|
+
return [...this.orderBySpecs];
|
|
51
|
+
}
|
|
52
|
+
getLimit() {
|
|
53
|
+
return this.limitValue;
|
|
54
|
+
}
|
|
55
|
+
getOffset() {
|
|
56
|
+
return this.offsetValue;
|
|
57
|
+
}
|
|
58
|
+
toCorrelatedSubquerySQL(rightTable, rightAlias, leftAlias) {
|
|
59
|
+
const selectPart = this.buildSelectPart();
|
|
60
|
+
const fromPart = mysqlFormat.ident(rightTable);
|
|
61
|
+
const wherePart = this.buildWherePart(leftAlias);
|
|
62
|
+
const groupByPart = this.buildGroupByPart();
|
|
63
|
+
const havingPart = this.buildHavingPart();
|
|
64
|
+
const orderByPart = this.buildOrderByPart();
|
|
65
|
+
const limitPart = this.buildLimitPart();
|
|
66
|
+
let innerQuery = `SELECT ${selectPart} FROM ${fromPart}`;
|
|
67
|
+
if (wherePart) {
|
|
68
|
+
innerQuery += ` WHERE ${wherePart}`;
|
|
69
|
+
}
|
|
70
|
+
if (groupByPart) {
|
|
71
|
+
innerQuery += ` GROUP BY ${groupByPart}`;
|
|
72
|
+
}
|
|
73
|
+
if (havingPart) {
|
|
74
|
+
innerQuery += ` HAVING ${havingPart}`;
|
|
75
|
+
}
|
|
76
|
+
if (orderByPart) {
|
|
77
|
+
innerQuery += ` ORDER BY ${orderByPart}`;
|
|
78
|
+
}
|
|
79
|
+
if (limitPart) {
|
|
80
|
+
innerQuery += limitPart;
|
|
81
|
+
}
|
|
82
|
+
const jsonObjectParts = this.buildJsonObjectParts();
|
|
83
|
+
let wrappedQuery;
|
|
84
|
+
if (jsonObjectParts) {
|
|
85
|
+
wrappedQuery = `SELECT COALESCE(JSON_ARRAYAGG(JSON_OBJECT(${jsonObjectParts})), CAST('[]' AS JSON)) AS ${mysqlFormat.ident(rightAlias)} FROM (${innerQuery}) AS \`sub\``;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
wrappedQuery = `SELECT COALESCE(JSON_ARRAYAGG(\`sub\`.\`__json\`), CAST('[]' AS JSON)) AS ${mysqlFormat.ident(rightAlias)} FROM (SELECT JSON_OBJECT(${this.buildAutoJsonObjectSQL(rightTable)}) AS \`__json\` FROM (${innerQuery}) AS \`inner_sub\`) AS \`sub\``;
|
|
89
|
+
}
|
|
90
|
+
return `(${wrappedQuery})`;
|
|
91
|
+
}
|
|
92
|
+
toSubquerySQL(rightTable, leftAlias) {
|
|
93
|
+
const selectPart = this.buildSelectPart();
|
|
94
|
+
const fromPart = mysqlFormat.ident(rightTable);
|
|
95
|
+
const wherePart = this.buildWherePart(leftAlias);
|
|
96
|
+
const groupByPart = this.buildGroupByPart();
|
|
97
|
+
const havingPart = this.buildHavingPart();
|
|
98
|
+
const orderByPart = this.buildOrderByPart();
|
|
99
|
+
const limitPart = this.buildLimitPart();
|
|
100
|
+
let query = `SELECT ${selectPart} FROM ${fromPart}`;
|
|
101
|
+
if (wherePart) {
|
|
102
|
+
query += ` WHERE ${wherePart}`;
|
|
103
|
+
}
|
|
104
|
+
if (groupByPart) {
|
|
105
|
+
query += ` GROUP BY ${groupByPart}`;
|
|
106
|
+
}
|
|
107
|
+
if (havingPart) {
|
|
108
|
+
query += ` HAVING ${havingPart}`;
|
|
109
|
+
}
|
|
110
|
+
if (orderByPart) {
|
|
111
|
+
query += ` ORDER BY ${orderByPart}`;
|
|
112
|
+
}
|
|
113
|
+
if (limitPart) {
|
|
114
|
+
query += limitPart;
|
|
115
|
+
}
|
|
116
|
+
return query;
|
|
117
|
+
}
|
|
118
|
+
buildSelectPart() {
|
|
119
|
+
if (this.selectColumns.length === 0) {
|
|
120
|
+
return '*';
|
|
121
|
+
}
|
|
122
|
+
return this.selectColumns
|
|
123
|
+
.map(col => mysqlColumnRefToSQLUnqualified(col))
|
|
124
|
+
.join(', ');
|
|
125
|
+
}
|
|
126
|
+
buildWherePart(_leftAlias) {
|
|
127
|
+
const parts = [];
|
|
128
|
+
for (const cond of this.conditions) {
|
|
129
|
+
if (cond.type === 'using' || cond.type === 'raw') {
|
|
130
|
+
if (cond.raw)
|
|
131
|
+
parts.push(cond.raw);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (cond.type === 'ilike') {
|
|
135
|
+
const leftSQL = mysqlColumnRefToSQL(cond.left);
|
|
136
|
+
const rightSQL = this.formatRightSide(cond.right);
|
|
137
|
+
parts.push(`LOWER(${leftSQL}) LIKE LOWER(${rightSQL})`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const leftSQL = mysqlColumnRefToSQL(cond.left);
|
|
141
|
+
const rightSQL = this.formatRightSide(cond.right);
|
|
142
|
+
parts.push(`${leftSQL} ${cond.operator} ${rightSQL}`);
|
|
143
|
+
}
|
|
144
|
+
if (this.whereConditions.length > 0) {
|
|
145
|
+
const whereSQL = buildMysqlConditionsSQL(this.whereConditions);
|
|
146
|
+
if (whereSQL) {
|
|
147
|
+
parts.push(whereSQL);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return parts.length > 0 ? parts.join(' AND ') : null;
|
|
151
|
+
}
|
|
152
|
+
buildGroupByPart() {
|
|
153
|
+
if (this.groupByColumns.length === 0) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return this.groupByColumns
|
|
157
|
+
.map(col => mysqlColumnRefToSQLUnqualified(col))
|
|
158
|
+
.join(', ');
|
|
159
|
+
}
|
|
160
|
+
buildHavingPart() {
|
|
161
|
+
if (this.havingConditions.length === 0) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return buildMysqlConditionsSQL(this.havingConditions);
|
|
165
|
+
}
|
|
166
|
+
buildOrderByPart() {
|
|
167
|
+
if (this.orderBySpecs.length === 0) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return this.orderBySpecs
|
|
171
|
+
.map(spec => `${mysqlColumnRefToSQLUnqualified(spec.column)} ${spec.direction}`)
|
|
172
|
+
.join(', ');
|
|
173
|
+
}
|
|
174
|
+
buildLimitPart() {
|
|
175
|
+
let sql = '';
|
|
176
|
+
if (this.limitValue !== undefined) {
|
|
177
|
+
sql += ` LIMIT ${this.limitValue}`;
|
|
178
|
+
}
|
|
179
|
+
if (this.offsetValue !== undefined) {
|
|
180
|
+
sql += ` OFFSET ${this.offsetValue}`;
|
|
181
|
+
}
|
|
182
|
+
return sql;
|
|
183
|
+
}
|
|
184
|
+
buildJsonObjectParts() {
|
|
185
|
+
if (this.selectColumns.length === 0) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return this.selectColumns
|
|
189
|
+
.map(col => `${mysqlFormat.literal(col.$sqlColumn)}, \`sub\`.${mysqlColumnRefToSQLUnqualified(col)}`)
|
|
190
|
+
.join(', ');
|
|
191
|
+
}
|
|
192
|
+
buildAutoJsonObjectSQL(_rightTable) {
|
|
193
|
+
return "'__all', \`inner_sub\`.*";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export function createMysqlJoinManyBuilder() {
|
|
197
|
+
return new MysqlJoinManyBuilder();
|
|
198
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { mysqlColumnRefToSQL, isMysqlColumnRef } from "./table-proxy.js";
|
|
2
|
+
import { MysqlConditionCollector, buildMysqlConditionsSQL } from "../condition/condition-collector.js";
|
|
3
|
+
import mysqlFormat from "../clients/shared/mysql-format.js";
|
|
4
|
+
import { MYSQL_JOIN_INTERNAL } from "./join-internals.js";
|
|
5
|
+
export class MysqlJoinConditionBuilder {
|
|
6
|
+
conditions = [];
|
|
7
|
+
whereConditions = [];
|
|
8
|
+
selectedColumns;
|
|
9
|
+
flatConfig;
|
|
10
|
+
equal(left, right) {
|
|
11
|
+
this.conditions.push({
|
|
12
|
+
type: 'equal',
|
|
13
|
+
left,
|
|
14
|
+
right,
|
|
15
|
+
operator: '='
|
|
16
|
+
});
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
notEqual(left, right) {
|
|
20
|
+
this.conditions.push({
|
|
21
|
+
type: 'notEqual',
|
|
22
|
+
left,
|
|
23
|
+
right,
|
|
24
|
+
operator: '!='
|
|
25
|
+
});
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
greaterThan(left, right) {
|
|
29
|
+
this.conditions.push({
|
|
30
|
+
type: 'greaterThan',
|
|
31
|
+
left,
|
|
32
|
+
right,
|
|
33
|
+
operator: '>'
|
|
34
|
+
});
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
lessThan(left, right) {
|
|
38
|
+
this.conditions.push({
|
|
39
|
+
type: 'lessThan',
|
|
40
|
+
left,
|
|
41
|
+
right,
|
|
42
|
+
operator: '<'
|
|
43
|
+
});
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
greaterThanOrEqual(left, right) {
|
|
47
|
+
this.conditions.push({
|
|
48
|
+
type: 'greaterThanOrEqual',
|
|
49
|
+
left,
|
|
50
|
+
right,
|
|
51
|
+
operator: '>='
|
|
52
|
+
});
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
lessThanOrEqual(left, right) {
|
|
56
|
+
this.conditions.push({
|
|
57
|
+
type: 'lessThanOrEqual',
|
|
58
|
+
left,
|
|
59
|
+
right,
|
|
60
|
+
operator: '<='
|
|
61
|
+
});
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
like(left, right) {
|
|
65
|
+
this.conditions.push({
|
|
66
|
+
type: 'like',
|
|
67
|
+
left,
|
|
68
|
+
right,
|
|
69
|
+
operator: 'LIKE'
|
|
70
|
+
});
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
ilike(left, right) {
|
|
74
|
+
this.conditions.push({
|
|
75
|
+
type: 'ilike',
|
|
76
|
+
left,
|
|
77
|
+
right,
|
|
78
|
+
operator: 'LIKE'
|
|
79
|
+
});
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
using(...columns) {
|
|
83
|
+
this.conditions.push({
|
|
84
|
+
type: 'using',
|
|
85
|
+
columns: columns
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
where(callback) {
|
|
90
|
+
const collector = new MysqlConditionCollector();
|
|
91
|
+
callback(collector);
|
|
92
|
+
this.whereConditions.push(...collector.getConditions());
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
select(...args) {
|
|
96
|
+
if (args.length === 1 && Array.isArray(args[0])) {
|
|
97
|
+
this.selectedColumns = args[0];
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.selectedColumns = args;
|
|
101
|
+
}
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
flat() {
|
|
105
|
+
if (!this.selectedColumns || this.selectedColumns.length === 0) {
|
|
106
|
+
throw new Error('Relq: .flat() requires .select() with explicit columns.');
|
|
107
|
+
}
|
|
108
|
+
this.flatConfig = { mode: 'prefix' };
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
get [MYSQL_JOIN_INTERNAL]() {
|
|
112
|
+
return {
|
|
113
|
+
toSQL: () => this.internalToSQL(),
|
|
114
|
+
isUsingJoin: () => this.internalIsUsingJoin(),
|
|
115
|
+
getUsingColumns: () => this.internalGetUsingColumns(),
|
|
116
|
+
toUsingSQL: () => this.internalToUsingSQL(),
|
|
117
|
+
getConditions: () => [...this.conditions],
|
|
118
|
+
getWhereConditions: () => [...this.whereConditions],
|
|
119
|
+
hasConditions: () => this.conditions.length > 0,
|
|
120
|
+
hasWhereConditions: () => this.whereConditions.length > 0,
|
|
121
|
+
getSelectedColumns: () => this.selectedColumns ?? null,
|
|
122
|
+
getFlatConfig: () => this.flatConfig ?? null,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
internalToSQL() {
|
|
126
|
+
const parts = [];
|
|
127
|
+
for (const cond of this.conditions) {
|
|
128
|
+
switch (cond.type) {
|
|
129
|
+
case 'using':
|
|
130
|
+
break;
|
|
131
|
+
case 'raw':
|
|
132
|
+
parts.push(cond.raw);
|
|
133
|
+
break;
|
|
134
|
+
case 'ilike': {
|
|
135
|
+
const leftSQL = mysqlColumnRefToSQL(cond.left);
|
|
136
|
+
const rightSQL = this.formatRightSide(cond.right);
|
|
137
|
+
parts.push(`LOWER(${leftSQL}) LIKE LOWER(${rightSQL})`);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
default: {
|
|
141
|
+
const leftSQL = mysqlColumnRefToSQL(cond.left);
|
|
142
|
+
const rightSQL = this.formatRightSide(cond.right);
|
|
143
|
+
parts.push(`${leftSQL} ${cond.operator} ${rightSQL}`);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (this.whereConditions.length > 0) {
|
|
149
|
+
const whereSQL = buildMysqlConditionsSQL(this.whereConditions);
|
|
150
|
+
if (whereSQL) {
|
|
151
|
+
parts.push(whereSQL);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return parts.join(' AND ');
|
|
155
|
+
}
|
|
156
|
+
internalIsUsingJoin() {
|
|
157
|
+
return this.conditions.length === 1 && this.conditions[0].type === 'using';
|
|
158
|
+
}
|
|
159
|
+
internalGetUsingColumns() {
|
|
160
|
+
if (!this.internalIsUsingJoin())
|
|
161
|
+
return null;
|
|
162
|
+
return this.conditions[0].columns || null;
|
|
163
|
+
}
|
|
164
|
+
internalToUsingSQL() {
|
|
165
|
+
const columns = this.internalGetUsingColumns();
|
|
166
|
+
if (!columns)
|
|
167
|
+
return null;
|
|
168
|
+
return `USING (${columns.map(c => mysqlFormat.ident(c)).join(', ')})`;
|
|
169
|
+
}
|
|
170
|
+
formatRightSide(right) {
|
|
171
|
+
if (isMysqlColumnRef(right)) {
|
|
172
|
+
return mysqlColumnRefToSQL(right);
|
|
173
|
+
}
|
|
174
|
+
if (right === null) {
|
|
175
|
+
return 'NULL';
|
|
176
|
+
}
|
|
177
|
+
if (typeof right === 'boolean') {
|
|
178
|
+
return right ? 'true' : 'false';
|
|
179
|
+
}
|
|
180
|
+
if (typeof right === 'number') {
|
|
181
|
+
return String(right);
|
|
182
|
+
}
|
|
183
|
+
if (typeof right === 'string') {
|
|
184
|
+
return mysqlFormat.literal(right);
|
|
185
|
+
}
|
|
186
|
+
if (right instanceof Date) {
|
|
187
|
+
return mysqlFormat.literal(right.toISOString());
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(right)) {
|
|
190
|
+
return `(${right.map(v => this.formatRightSide(v)).join(', ')})`;
|
|
191
|
+
}
|
|
192
|
+
return mysqlFormat.literal(JSON.stringify(right));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export function createMysqlJoinConditionBuilder() {
|
|
196
|
+
return new MysqlJoinConditionBuilder();
|
|
197
|
+
}
|