diff --git a/src/server/templates/typescript.ts b/src/server/templates/typescript.ts index 4f9cac03..dda78f55 100644 --- a/src/server/templates/typescript.ts +++ b/src/server/templates/typescript.ts @@ -144,6 +144,16 @@ export type Database = { views, }) + if (column.name.toLowerCase().startsWith("decimal")) { + console.log("YOYOYOYO Insert", `'${column.name}'`, `'${column.format}'`) + } + + // Numeric types can be inserted as strings to preserve + // precision. + if (column.format === "numeric") { + output += '| string' + } + if (column.is_nullable) { output += '| null' } @@ -166,6 +176,12 @@ export type Database = { views, })}` + // Numeric types can be inserted as strings to preserve + // precision. + if (column.format === "numeric") { + output += '| string' + } + if (column.is_nullable) { output += '| null' } diff --git a/test/server/typegen.ts b/test/server/typegen.ts index 76ac6218..5b38f1be 100644 --- a/test/server/typegen.ts +++ b/test/server/typegen.ts @@ -227,13 +227,13 @@ test('typegen: typescript', async () => { status: Database["public"]["Enums"]["user_status"] | null } Insert: { - decimal?: number | null + decimal?: number | string | null id?: number name?: string | null status?: Database["public"]["Enums"]["user_status"] | null } Update: { - decimal?: number | null + decimal?: number | string | null id?: number name?: string | null status?: Database["public"]["Enums"]["user_status"] | null @@ -870,13 +870,13 @@ test('typegen: typescript w/ one-to-one relationships', async () => { status: Database["public"]["Enums"]["user_status"] | null } Insert: { - decimal?: number | null + decimal?: number | string | null id?: number name?: string | null status?: Database["public"]["Enums"]["user_status"] | null } Update: { - decimal?: number | null + decimal?: number | string | null id?: number name?: string | null status?: Database["public"]["Enums"]["user_status"] | null @@ -1528,13 +1528,13 @@ test('typegen: typescript w/ postgrestVersion', async () => { status: Database["public"]["Enums"]["user_status"] | null } Insert: { - decimal?: number | null + decimal?: number | string | null id?: number name?: string | null status?: Database["public"]["Enums"]["user_status"] | null } Update: { - decimal?: number | null + decimal?: number | string | null id?: number name?: string | null status?: Database["public"]["Enums"]["user_status"] | null @@ -1682,7 +1682,7 @@ test('typegen: typescript w/ postgrestVersion', async () => { status: Database["public"]["Enums"]["user_status"] | null } Insert: { - decimal?: number | null + decimal?: number | string | null id?: number | null name?: string | null status?: Database["public"]["Enums"]["user_status"] | null