( transform?: (_: string) => string, transformJson = true )
| 819 | )) |
| 820 | |
| 821 | /** |
| 822 | * Creates a layer from a concrete PostgreSQL pool configuration, providing both `PgClient` and `SqlClient`. |
| 823 | * |
| 824 | * @category layers |
| 825 | * @since 4.0.0 |
| 826 | */ |
| 827 | export const layer = ( |
| 828 | config: PgPoolConfig |
| 829 | ): Layer.Layer<PgClient | Client.SqlClient, SqlError> => layerFrom(make(config)) |
| 830 | |
| 831 | /** |
| 832 | * Creates the PostgreSQL statement compiler, using `$1` placeholders, double-quoted identifiers, PostgreSQL returning clauses, and optional JSON value transformation. |
| 833 | * |
| 834 | * @category constructors |
| 835 | * @since 4.0.0 |
| 836 | */ |
| 837 | export const makeCompiler = ( |
| 838 | transform?: (_: string) => string, |
| 839 | transformJson = true |
| 840 | ): Statement.Compiler => { |
| 841 | const transformValue = transformJson && transform |
| 842 | ? Statement.defaultTransforms(transform).value |
| 843 | : undefined |
| 844 | |
| 845 | return Statement.makeCompiler<PgCustom>({ |
| 846 | dialect: "pg", |
| 847 | placeholder(_) { |
| 848 | return `$${_}` |
| 849 | }, |
| 850 | onIdentifier: transform ? |
| 851 | function(value, withoutTransform) { |
| 852 | return withoutTransform ? escape(value) : escape(transform(value)) |
| 853 | } : |
| 854 | escape, |
| 855 | onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) { |
| 856 | return [ |
| 857 | `(values ${placeholders}) AS ${valueAlias}${valueColumns}${returning ? ` RETURNING ${returning[0]}` : ""}`, |
| 858 | returning ? |
| 859 | values.flat().concat(returning[1]) : |
| 860 | values.flat() |
| 861 | ] |
| 862 | }, |
| 863 | onCustom(type, placeholder, withoutTransform) { |
| 864 | switch (type.kind) { |
| 865 | case "PgJson": { |
no test coverage detected
searching dependent graphs…