@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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
export class MysqlForeignKeyResolutionError extends Error {
|
|
2
|
+
fromTable;
|
|
3
|
+
toTable;
|
|
4
|
+
constructor(fromTable, toTable, message) {
|
|
5
|
+
super(message || `No foreign key relationship found between "${fromTable}" and "${toTable}"`);
|
|
6
|
+
this.fromTable = fromTable;
|
|
7
|
+
this.toTable = toTable;
|
|
8
|
+
this.name = 'MysqlForeignKeyResolutionError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function resolveMysqlForeignKey(schema, fromTableKey, toTableKey) {
|
|
12
|
+
const fromTableDef = schema[fromTableKey];
|
|
13
|
+
const toTableDef = schema[toTableKey];
|
|
14
|
+
if (!fromTableDef || !toTableDef) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const fromTableName = fromTableDef.$name;
|
|
18
|
+
const toTableName = toTableDef.$name;
|
|
19
|
+
if (fromTableDef.$foreignKeys) {
|
|
20
|
+
for (const fk of fromTableDef.$foreignKeys) {
|
|
21
|
+
if (fk.references.table === toTableName || fk.references.table === toTableKey) {
|
|
22
|
+
if (fk.columns.length > 0 && fk.references.columns.length > 0) {
|
|
23
|
+
return {
|
|
24
|
+
fromTable: fromTableName,
|
|
25
|
+
fromColumn: resolveColumnName(fromTableDef, fk.columns[0]),
|
|
26
|
+
toTable: toTableName,
|
|
27
|
+
toColumn: resolveColumnName(toTableDef, fk.references.columns[0]),
|
|
28
|
+
direction: 'forward',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (toTableDef.$foreignKeys) {
|
|
35
|
+
const candidates = [];
|
|
36
|
+
for (const fk of toTableDef.$foreignKeys) {
|
|
37
|
+
if (fk.references.table === fromTableName || fk.references.table === fromTableKey) {
|
|
38
|
+
if (fk.columns.length > 0 && fk.references.columns.length > 0) {
|
|
39
|
+
candidates.push(fk);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (candidates.length > 0) {
|
|
44
|
+
let best = candidates[0];
|
|
45
|
+
if (candidates.length > 1) {
|
|
46
|
+
let bestScore = 0;
|
|
47
|
+
const columns = toTableDef.$columns || {};
|
|
48
|
+
for (const candidate of candidates) {
|
|
49
|
+
const colName = candidate.columns[0];
|
|
50
|
+
for (const [propKey, colDef] of Object.entries(columns)) {
|
|
51
|
+
if (!colDef)
|
|
52
|
+
continue;
|
|
53
|
+
const sqlName = colDef.$columnName || colDef.$sqlName;
|
|
54
|
+
if (sqlName !== colName && propKey !== colName)
|
|
55
|
+
continue;
|
|
56
|
+
let score = 0;
|
|
57
|
+
if (colDef.$primaryKey === true)
|
|
58
|
+
score = 2;
|
|
59
|
+
else if (colDef.$nullable === false || colDef.$notNull === true)
|
|
60
|
+
score = 1;
|
|
61
|
+
if (score > bestScore) {
|
|
62
|
+
bestScore = score;
|
|
63
|
+
best = candidate;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
fromTable: fromTableName,
|
|
71
|
+
fromColumn: resolveColumnName(fromTableDef, best.references.columns[0]),
|
|
72
|
+
toTable: toTableName,
|
|
73
|
+
toColumn: resolveColumnName(toTableDef, best.columns[0]),
|
|
74
|
+
direction: 'reverse',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (const [_key, tableDef] of Object.entries(schema)) {
|
|
79
|
+
if (tableDef === fromTableDef || tableDef === toTableDef)
|
|
80
|
+
continue;
|
|
81
|
+
if (!tableDef.$foreignKeys)
|
|
82
|
+
continue;
|
|
83
|
+
for (const fk of tableDef.$foreignKeys) {
|
|
84
|
+
if (fk.references.table === fromTableName || fk.references.table === fromTableKey) {
|
|
85
|
+
const otherFk = tableDef.$foreignKeys.find(f => f !== fk && (f.references.table === toTableName || f.references.table === toTableKey));
|
|
86
|
+
if (otherFk) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
export function resolveMysqlForeignKeyOrThrow(schema, fromTableKey, toTableKey) {
|
|
95
|
+
const result = resolveMysqlForeignKey(schema, fromTableKey, toTableKey);
|
|
96
|
+
if (!result) {
|
|
97
|
+
const available = getAvailableMysqlRelations(schema, fromTableKey);
|
|
98
|
+
let message = `No foreign key relationship found between "${fromTableKey}" and "${toTableKey}".`;
|
|
99
|
+
if (available.length > 0) {
|
|
100
|
+
message += ` Available FK relations from "${fromTableKey}": ${available.join(', ')}.`;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
message += ` No foreign keys defined on "${fromTableKey}".`;
|
|
104
|
+
}
|
|
105
|
+
message += ' Use an explicit join condition instead.';
|
|
106
|
+
throw new MysqlForeignKeyResolutionError(fromTableKey, toTableKey, message);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
export function getAvailableMysqlRelations(schema, tableKey) {
|
|
111
|
+
const tableDef = schema[tableKey];
|
|
112
|
+
if (!tableDef || !tableDef.$foreignKeys) {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
return tableDef.$foreignKeys.map(fk => {
|
|
116
|
+
const cols = fk.columns.join(', ');
|
|
117
|
+
const refCols = fk.references.columns.join(', ');
|
|
118
|
+
return `(${cols}) → ${fk.references.table}(${refCols})`;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export function getAllMysqlForeignKeys(schema, tableKey) {
|
|
122
|
+
const tableDef = schema[tableKey];
|
|
123
|
+
if (!tableDef) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const tableName = tableDef.$name;
|
|
127
|
+
const results = [];
|
|
128
|
+
if (tableDef.$foreignKeys) {
|
|
129
|
+
for (const fk of tableDef.$foreignKeys) {
|
|
130
|
+
const targetKey = findTableKeyByName(schema, fk.references.table);
|
|
131
|
+
const targetDef = targetKey ? schema[targetKey] : null;
|
|
132
|
+
if (fk.columns.length > 0 && fk.references.columns.length > 0) {
|
|
133
|
+
results.push({
|
|
134
|
+
fromTable: tableName,
|
|
135
|
+
fromColumn: resolveColumnName(tableDef, fk.columns[0]),
|
|
136
|
+
toTable: fk.references.table,
|
|
137
|
+
toColumn: targetDef
|
|
138
|
+
? resolveColumnName(targetDef, fk.references.columns[0])
|
|
139
|
+
: fk.references.columns[0],
|
|
140
|
+
direction: 'forward',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (const [otherKey, otherDef] of Object.entries(schema)) {
|
|
146
|
+
if (otherKey === tableKey)
|
|
147
|
+
continue;
|
|
148
|
+
if (!otherDef.$foreignKeys)
|
|
149
|
+
continue;
|
|
150
|
+
for (const fk of otherDef.$foreignKeys) {
|
|
151
|
+
if (fk.references.table === tableName || fk.references.table === tableKey) {
|
|
152
|
+
if (fk.columns.length > 0 && fk.references.columns.length > 0) {
|
|
153
|
+
results.push({
|
|
154
|
+
fromTable: tableName,
|
|
155
|
+
fromColumn: resolveColumnName(tableDef, fk.references.columns[0]),
|
|
156
|
+
toTable: otherDef.$name,
|
|
157
|
+
toColumn: resolveColumnName(otherDef, fk.columns[0]),
|
|
158
|
+
direction: 'reverse',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return results;
|
|
165
|
+
}
|
|
166
|
+
function resolveColumnName(tableDef, columnKey) {
|
|
167
|
+
if (tableDef.$columns && tableDef.$columns[columnKey]) {
|
|
168
|
+
return tableDef.$columns[columnKey].$columnName || columnKey;
|
|
169
|
+
}
|
|
170
|
+
return columnKey;
|
|
171
|
+
}
|
|
172
|
+
function findTableKeyByName(schema, tableName) {
|
|
173
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
174
|
+
if (def.$name === tableName || key === tableName) {
|
|
175
|
+
return key;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { resolveMysqlForeignKey, resolveMysqlForeignKeyOrThrow, getAvailableMysqlRelations, getAllMysqlForeignKeys, MysqlForeignKeyResolutionError, } from "./fk-resolver.js";
|
|
2
|
+
export { deserializeMysqlValue, serializeMysqlValue, deserializeMysqlRow, deserializeMysqlRows, serializeMysqlRow, extractMysqlSchemaColumns, } from "./type-coercion.js";
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
const BIGINT_TYPES = new Set(['BIGINT', 'BIGINT UNSIGNED', 'SERIAL']);
|
|
2
|
+
const DATE_TYPES = new Set(['DATE', 'DATETIME', 'TIMESTAMP']);
|
|
3
|
+
const JSON_TYPES = new Set(['JSON']);
|
|
4
|
+
const DECIMAL_TYPES = new Set(['DECIMAL', 'NUMERIC', 'DEC', 'FIXED']);
|
|
5
|
+
export function deserializeMysqlValue(value, mysqlType) {
|
|
6
|
+
if (value === null || value === undefined) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
const upperType = mysqlType.toUpperCase();
|
|
10
|
+
if (BIGINT_TYPES.has(upperType) || upperType.startsWith('BIGINT')) {
|
|
11
|
+
if (typeof value === 'string') {
|
|
12
|
+
return BigInt(value);
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'number') {
|
|
15
|
+
return BigInt(value);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (DATE_TYPES.has(upperType) || upperType.startsWith('DATETIME') || upperType.startsWith('TIMESTAMP')) {
|
|
20
|
+
if (value instanceof Date) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
24
|
+
return new Date(value);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
if (JSON_TYPES.has(upperType)) {
|
|
29
|
+
if (typeof value === 'string') {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(value);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
if (DECIMAL_TYPES.has(upperType) || upperType.startsWith('DECIMAL') || upperType.startsWith('NUMERIC')) {
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
const num = Number(value);
|
|
42
|
+
return Number.isFinite(num) ? num : value;
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
if (upperType === 'TINYINT(1)' || upperType === 'TINYINT' || upperType === 'BOOL' || upperType === 'BOOLEAN') {
|
|
47
|
+
if (typeof value === 'number') {
|
|
48
|
+
return value !== 0;
|
|
49
|
+
}
|
|
50
|
+
if (Buffer.isBuffer(value)) {
|
|
51
|
+
return value[0] !== 0;
|
|
52
|
+
}
|
|
53
|
+
return Boolean(value);
|
|
54
|
+
}
|
|
55
|
+
if (upperType === 'BIT(1)' || upperType === 'BIT') {
|
|
56
|
+
if (Buffer.isBuffer(value)) {
|
|
57
|
+
return value[0] !== 0;
|
|
58
|
+
}
|
|
59
|
+
if (typeof value === 'number') {
|
|
60
|
+
return value !== 0;
|
|
61
|
+
}
|
|
62
|
+
return Boolean(value);
|
|
63
|
+
}
|
|
64
|
+
if (upperType === 'SET' || upperType.startsWith('SET(')) {
|
|
65
|
+
if (typeof value === 'string') {
|
|
66
|
+
return value === '' ? [] : value.split(',');
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
export function serializeMysqlValue(value, mysqlType) {
|
|
73
|
+
if (value === null || value === undefined) {
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
const upperType = mysqlType.toUpperCase();
|
|
77
|
+
if (BIGINT_TYPES.has(upperType) || upperType.startsWith('BIGINT')) {
|
|
78
|
+
if (typeof value === 'bigint') {
|
|
79
|
+
return value.toString();
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
if (DATE_TYPES.has(upperType) || upperType.startsWith('DATETIME') || upperType.startsWith('TIMESTAMP')) {
|
|
84
|
+
if (value instanceof Date) {
|
|
85
|
+
return value.toISOString();
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
if (JSON_TYPES.has(upperType)) {
|
|
90
|
+
if (typeof value === 'object' && value !== null) {
|
|
91
|
+
return JSON.stringify(value);
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
if (upperType === 'TINYINT(1)' || upperType === 'TINYINT' || upperType === 'BOOL' || upperType === 'BOOLEAN') {
|
|
96
|
+
if (typeof value === 'boolean') {
|
|
97
|
+
return value ? 1 : 0;
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
if (upperType === 'SET' || upperType.startsWith('SET(')) {
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
return value.join(',');
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
export function deserializeMysqlRow(row, schema) {
|
|
110
|
+
const result = {};
|
|
111
|
+
const columnMap = new Map();
|
|
112
|
+
for (const [key, config] of Object.entries(schema)) {
|
|
113
|
+
const dbColumnName = config.$columnName || key;
|
|
114
|
+
const sqlType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'VARCHAR');
|
|
115
|
+
columnMap.set(dbColumnName, { key, type: sqlType });
|
|
116
|
+
}
|
|
117
|
+
for (const [dbColumn, value] of Object.entries(row)) {
|
|
118
|
+
const mapping = columnMap.get(dbColumn);
|
|
119
|
+
if (mapping) {
|
|
120
|
+
result[mapping.key] = deserializeMysqlValue(value, mapping.type);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
result[dbColumn] = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
export function deserializeMysqlRows(rows, schema) {
|
|
129
|
+
return rows.map(row => deserializeMysqlRow(row, schema));
|
|
130
|
+
}
|
|
131
|
+
export function serializeMysqlRow(row, schema) {
|
|
132
|
+
const result = {};
|
|
133
|
+
for (const [key, value] of Object.entries(row)) {
|
|
134
|
+
const config = schema[key];
|
|
135
|
+
if (config) {
|
|
136
|
+
const sqlType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'VARCHAR');
|
|
137
|
+
result[key] = serializeMysqlValue(value, sqlType);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
result[key] = value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
export function extractMysqlSchemaColumns(tableDefinition) {
|
|
146
|
+
if (tableDefinition && tableDefinition.$columns) {
|
|
147
|
+
return tableDefinition.$columns;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MysqlWindowBuilder } from "./window-builder.js";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import mysqlFormat from "../clients/shared/mysql-format.js";
|
|
2
|
+
export class MysqlWindowBuilder {
|
|
3
|
+
partitionColumns = [];
|
|
4
|
+
orderColumns = [];
|
|
5
|
+
frameStart;
|
|
6
|
+
frameEnd;
|
|
7
|
+
frameMode;
|
|
8
|
+
partitionBy(...columns) {
|
|
9
|
+
this.partitionColumns.push(...columns);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
orderBy(column, direction = 'ASC') {
|
|
13
|
+
this.orderColumns.push({ column, direction });
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
rows(start, end) {
|
|
17
|
+
this.frameMode = 'ROWS';
|
|
18
|
+
this.frameStart = typeof start === 'number' ? `${start} PRECEDING` : start;
|
|
19
|
+
this.frameEnd = end ? (typeof end === 'number' ? `${end} FOLLOWING` : end) : 'CURRENT ROW';
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
range(start, end) {
|
|
23
|
+
this.frameMode = 'RANGE';
|
|
24
|
+
this.frameStart = typeof start === 'number' ? `${start} PRECEDING` : start;
|
|
25
|
+
this.frameEnd = end ? (typeof end === 'number' ? `${end} FOLLOWING` : end) : 'CURRENT ROW';
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
groups(start, end) {
|
|
29
|
+
this.frameMode = 'GROUPS';
|
|
30
|
+
this.frameStart = typeof start === 'number' ? `${start} PRECEDING` : start;
|
|
31
|
+
this.frameEnd = end ? (typeof end === 'number' ? `${end} FOLLOWING` : end) : 'CURRENT ROW';
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
toString() {
|
|
35
|
+
const parts = [];
|
|
36
|
+
if (this.partitionColumns.length > 0) {
|
|
37
|
+
parts.push(`PARTITION BY ${this.partitionColumns.map(c => mysqlFormat.ident(c)).join(', ')}`);
|
|
38
|
+
}
|
|
39
|
+
if (this.orderColumns.length > 0) {
|
|
40
|
+
parts.push(`ORDER BY ${this.orderColumns.map(o => `${mysqlFormat.ident(o.column)} ${o.direction}`).join(', ')}`);
|
|
41
|
+
}
|
|
42
|
+
if (this.frameMode && this.frameStart) {
|
|
43
|
+
parts.push(`${this.frameMode} BETWEEN ${this.frameStart} AND ${this.frameEnd}`);
|
|
44
|
+
}
|
|
45
|
+
return parts.join(' ');
|
|
46
|
+
}
|
|
47
|
+
rowNumber() {
|
|
48
|
+
return `ROW_NUMBER() OVER (${this.toString()})`;
|
|
49
|
+
}
|
|
50
|
+
rank() {
|
|
51
|
+
return `RANK() OVER (${this.toString()})`;
|
|
52
|
+
}
|
|
53
|
+
denseRank() {
|
|
54
|
+
return `DENSE_RANK() OVER (${this.toString()})`;
|
|
55
|
+
}
|
|
56
|
+
lag(column, offset = 1, defaultValue) {
|
|
57
|
+
const def = defaultValue !== undefined ? `, ${mysqlFormat.literal(defaultValue)}` : '';
|
|
58
|
+
return `LAG(${mysqlFormat.ident(column)}, ${offset}${def}) OVER (${this.toString()})`;
|
|
59
|
+
}
|
|
60
|
+
lead(column, offset = 1, defaultValue) {
|
|
61
|
+
const def = defaultValue !== undefined ? `, ${mysqlFormat.literal(defaultValue)}` : '';
|
|
62
|
+
return `LEAD(${mysqlFormat.ident(column)}, ${offset}${def}) OVER (${this.toString()})`;
|
|
63
|
+
}
|
|
64
|
+
firstValue(column) {
|
|
65
|
+
return `FIRST_VALUE(${mysqlFormat.ident(column)}) OVER (${this.toString()})`;
|
|
66
|
+
}
|
|
67
|
+
lastValue(column) {
|
|
68
|
+
return `LAST_VALUE(${mysqlFormat.ident(column)}) OVER (${this.toString()})`;
|
|
69
|
+
}
|
|
70
|
+
nthValue(column, n) {
|
|
71
|
+
return `NTH_VALUE(${mysqlFormat.ident(column)}, ${n}) OVER (${this.toString()})`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const ALLOYDB_CAPABILITIES = {
|
|
2
|
+
returning: true,
|
|
3
|
+
lateral: true,
|
|
4
|
+
distinctOn: true,
|
|
5
|
+
listenNotify: true,
|
|
6
|
+
pooling: true,
|
|
7
|
+
cursors: true,
|
|
8
|
+
jsonb: true,
|
|
9
|
+
arrays: true,
|
|
10
|
+
ranges: true,
|
|
11
|
+
fullTextSearch: true,
|
|
12
|
+
upsert: true,
|
|
13
|
+
forUpdateSkipLocked: true,
|
|
14
|
+
windowFunctions: true,
|
|
15
|
+
cte: true,
|
|
16
|
+
recursiveCte: true,
|
|
17
|
+
explainAnalyze: true,
|
|
18
|
+
savepoints: true,
|
|
19
|
+
createTableAs: true,
|
|
20
|
+
materializedViews: true,
|
|
21
|
+
storedProcedures: true,
|
|
22
|
+
triggers: true,
|
|
23
|
+
sequences: true,
|
|
24
|
+
copy: true,
|
|
25
|
+
vacuum: true,
|
|
26
|
+
identifierQuote: '"',
|
|
27
|
+
parameterStyle: 'dollar',
|
|
28
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ListenerConnection } from "
|
|
1
|
+
import { ListenerConnection } from "../../pubsub/listener-connection.js";
|
|
2
2
|
import { mergeWithPgEnv, validateEnvConfig } from "../../../utils/env-resolver.js";
|
|
3
3
|
import { PgBase } from "../shared/pg-base.js";
|
|
4
|
-
import {
|
|
5
|
-
export class
|
|
6
|
-
dialect = '
|
|
7
|
-
capabilities =
|
|
4
|
+
import { ALLOYDB_CAPABILITIES } from "./capabilities.js";
|
|
5
|
+
export class RelqAlloyDB extends PgBase {
|
|
6
|
+
dialect = 'alloydb';
|
|
7
|
+
capabilities = ALLOYDB_CAPABILITIES;
|
|
8
8
|
listener = null;
|
|
9
9
|
constructor(schema, config = {}) {
|
|
10
|
-
validateEnvConfig('
|
|
11
|
-
const resolvedConfig = mergeWithPgEnv({ ...config, dialect: '
|
|
10
|
+
validateEnvConfig('alloydb', config);
|
|
11
|
+
const resolvedConfig = mergeWithPgEnv({ ...config, dialect: 'alloydb' });
|
|
12
12
|
super(schema, resolvedConfig);
|
|
13
13
|
}
|
|
14
14
|
async subscribe(channel, callback) {
|
|
@@ -19,7 +19,7 @@ export class RelqPostgres extends PgBase {
|
|
|
19
19
|
user: this.config.user,
|
|
20
20
|
password: this.config.password,
|
|
21
21
|
database: this.config.database,
|
|
22
|
-
connectionString: this.config.
|
|
22
|
+
connectionString: this.config.url,
|
|
23
23
|
ssl: this.config.ssl
|
|
24
24
|
});
|
|
25
25
|
this.listener.on('error', (err) => this.emitter.emit('listenerError', err));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const AURORA_CAPABILITIES = {
|
|
2
|
+
returning: true,
|
|
3
|
+
lateral: true,
|
|
4
|
+
distinctOn: true,
|
|
5
|
+
listenNotify: true,
|
|
6
|
+
pooling: true,
|
|
7
|
+
cursors: true,
|
|
8
|
+
jsonb: true,
|
|
9
|
+
arrays: true,
|
|
10
|
+
ranges: true,
|
|
11
|
+
fullTextSearch: true,
|
|
12
|
+
upsert: true,
|
|
13
|
+
forUpdateSkipLocked: true,
|
|
14
|
+
windowFunctions: true,
|
|
15
|
+
cte: true,
|
|
16
|
+
recursiveCte: true,
|
|
17
|
+
explainAnalyze: true,
|
|
18
|
+
savepoints: true,
|
|
19
|
+
createTableAs: true,
|
|
20
|
+
materializedViews: true,
|
|
21
|
+
storedProcedures: true,
|
|
22
|
+
triggers: true,
|
|
23
|
+
sequences: true,
|
|
24
|
+
copy: true,
|
|
25
|
+
vacuum: true,
|
|
26
|
+
identifierQuote: '"',
|
|
27
|
+
parameterStyle: 'dollar',
|
|
28
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ListenerConnection } from "../../pubsub/listener-connection.js";
|
|
2
|
+
import { mergeWithPgEnv, validateEnvConfig } from "../../../utils/env-resolver.js";
|
|
3
|
+
import { PgBase } from "../shared/pg-base.js";
|
|
4
|
+
import { AURORA_CAPABILITIES } from "./capabilities.js";
|
|
5
|
+
export class RelqAurora extends PgBase {
|
|
6
|
+
dialect = 'aurora';
|
|
7
|
+
capabilities = AURORA_CAPABILITIES;
|
|
8
|
+
listener = null;
|
|
9
|
+
constructor(schema, config = {}) {
|
|
10
|
+
validateEnvConfig('aurora', config);
|
|
11
|
+
const resolvedConfig = mergeWithPgEnv({ ...config, dialect: 'aurora' });
|
|
12
|
+
super(schema, resolvedConfig);
|
|
13
|
+
}
|
|
14
|
+
async subscribe(channel, callback) {
|
|
15
|
+
if (!this.listener) {
|
|
16
|
+
this.listener = new ListenerConnection({
|
|
17
|
+
host: this.config.host,
|
|
18
|
+
port: this.config.port,
|
|
19
|
+
user: this.config.user,
|
|
20
|
+
password: this.config.password,
|
|
21
|
+
database: this.config.database,
|
|
22
|
+
connectionString: this.config.url,
|
|
23
|
+
ssl: this.config.ssl
|
|
24
|
+
});
|
|
25
|
+
this.listener.on('error', (err) => this.emitter.emit('listenerError', err));
|
|
26
|
+
this.listener.on('connect', () => this.emitter.emit('listenerConnect'));
|
|
27
|
+
}
|
|
28
|
+
const sub = await this.listener.subscribe(channel);
|
|
29
|
+
sub.on('notification', callback);
|
|
30
|
+
return () => sub.close();
|
|
31
|
+
}
|
|
32
|
+
async _close() {
|
|
33
|
+
if (this.listener) {
|
|
34
|
+
await this.listener.close();
|
|
35
|
+
this.listener = null;
|
|
36
|
+
}
|
|
37
|
+
await super._close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const CITUS_CAPABILITIES = {
|
|
2
|
+
returning: true,
|
|
3
|
+
lateral: true,
|
|
4
|
+
distinctOn: true,
|
|
5
|
+
listenNotify: true,
|
|
6
|
+
pooling: true,
|
|
7
|
+
cursors: true,
|
|
8
|
+
jsonb: true,
|
|
9
|
+
arrays: true,
|
|
10
|
+
ranges: true,
|
|
11
|
+
fullTextSearch: true,
|
|
12
|
+
upsert: true,
|
|
13
|
+
forUpdateSkipLocked: true,
|
|
14
|
+
windowFunctions: true,
|
|
15
|
+
cte: true,
|
|
16
|
+
recursiveCte: true,
|
|
17
|
+
explainAnalyze: true,
|
|
18
|
+
savepoints: true,
|
|
19
|
+
createTableAs: true,
|
|
20
|
+
materializedViews: true,
|
|
21
|
+
storedProcedures: true,
|
|
22
|
+
triggers: true,
|
|
23
|
+
sequences: true,
|
|
24
|
+
copy: true,
|
|
25
|
+
vacuum: true,
|
|
26
|
+
identifierQuote: '"',
|
|
27
|
+
parameterStyle: 'dollar',
|
|
28
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ListenerConnection } from "../../pubsub/listener-connection.js";
|
|
2
|
+
import { mergeWithPgEnv, validateEnvConfig } from "../../../utils/env-resolver.js";
|
|
3
|
+
import { PgBase } from "../shared/pg-base.js";
|
|
4
|
+
import { CITUS_CAPABILITIES } from "./capabilities.js";
|
|
5
|
+
export class RelqCitus extends PgBase {
|
|
6
|
+
dialect = 'citus';
|
|
7
|
+
capabilities = CITUS_CAPABILITIES;
|
|
8
|
+
listener = null;
|
|
9
|
+
constructor(schema, config = {}) {
|
|
10
|
+
validateEnvConfig('citus', config);
|
|
11
|
+
const resolvedConfig = mergeWithPgEnv({ ...config, dialect: 'citus' });
|
|
12
|
+
super(schema, resolvedConfig);
|
|
13
|
+
}
|
|
14
|
+
async subscribe(channel, callback) {
|
|
15
|
+
if (!this.listener) {
|
|
16
|
+
this.listener = new ListenerConnection({
|
|
17
|
+
host: this.config.host,
|
|
18
|
+
port: this.config.port,
|
|
19
|
+
user: this.config.user,
|
|
20
|
+
password: this.config.password,
|
|
21
|
+
database: this.config.database,
|
|
22
|
+
connectionString: this.config.url,
|
|
23
|
+
ssl: this.config.ssl
|
|
24
|
+
});
|
|
25
|
+
this.listener.on('error', (err) => this.emitter.emit('listenerError', err));
|
|
26
|
+
this.listener.on('connect', () => this.emitter.emit('listenerConnect'));
|
|
27
|
+
}
|
|
28
|
+
const sub = await this.listener.subscribe(channel);
|
|
29
|
+
sub.on('notification', callback);
|
|
30
|
+
return () => sub.close();
|
|
31
|
+
}
|
|
32
|
+
async _close() {
|
|
33
|
+
if (this.listener) {
|
|
34
|
+
await this.listener.close();
|
|
35
|
+
this.listener = null;
|
|
36
|
+
}
|
|
37
|
+
await super._close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const NEON_CAPABILITIES = {
|
|
2
|
+
returning: true,
|
|
3
|
+
lateral: true,
|
|
4
|
+
distinctOn: true,
|
|
5
|
+
listenNotify: true,
|
|
6
|
+
pooling: true,
|
|
7
|
+
cursors: true,
|
|
8
|
+
jsonb: true,
|
|
9
|
+
arrays: true,
|
|
10
|
+
ranges: true,
|
|
11
|
+
fullTextSearch: true,
|
|
12
|
+
upsert: true,
|
|
13
|
+
forUpdateSkipLocked: true,
|
|
14
|
+
windowFunctions: true,
|
|
15
|
+
cte: true,
|
|
16
|
+
recursiveCte: true,
|
|
17
|
+
explainAnalyze: true,
|
|
18
|
+
savepoints: true,
|
|
19
|
+
createTableAs: true,
|
|
20
|
+
materializedViews: true,
|
|
21
|
+
storedProcedures: true,
|
|
22
|
+
triggers: true,
|
|
23
|
+
sequences: true,
|
|
24
|
+
copy: true,
|
|
25
|
+
vacuum: true,
|
|
26
|
+
identifierQuote: '"',
|
|
27
|
+
parameterStyle: 'dollar',
|
|
28
|
+
};
|