sevenwestonroads
sevenwestonroads
DTDrizzle Team
Created by sevenwestonroads on 1/21/2024 in #help
Using json_agg does not format correctly
I didn't know it existed @Angelelz - do you mind sharing an example? Thank you !
8 replies
DTDrizzle Team
Created by sevenwestonroads on 1/19/2024 in #help
ENUM not detected
Upgrading my DRIZZLE packages worked - thank you team ! ❤️
2 replies
DTDrizzle Team
Created by sevenwestonroads on 12/18/2023 in #help
What work is required to support ClickHouse?
yes! it's an SQL-like dialect they say they supports a declarative query language based on SQL that is identical to the ANSI SQL standard in many cases.
5 replies
DTDrizzle Team
Created by sevenwestonroads on 10/10/2023 in #help
Psql Array of text and `createSelectSchema`, `createInsertSchema`
I was thanking in advance @ByteBender 😂😂🙏
7 replies
DTDrizzle Team
Created by sevenwestonroads on 10/10/2023 in #help
Psql Array of text and `createSelectSchema`, `createInsertSchema`
Thanks !!!
7 replies
DTDrizzle Team
Created by sevenwestonroads on 9/20/2023 in #help
Best practice on connections for PostgreSQL
Like below @rphlmr ?
import { remember } from '@epic-web/remember';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const pool = postgres(process.env.DATABASE_URL as string);

const client = remember('client', () => drizzle(pool, { logger: true }));

export { client, pool };
import { remember } from '@epic-web/remember';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const pool = postgres(process.env.DATABASE_URL as string);

const client = remember('client', () => drizzle(pool, { logger: true }));

export { client, pool };
8 replies
DTDrizzle Team
Created by sevenwestonroads on 9/20/2023 in #help
Best practice on connections for PostgreSQL
Yes !
8 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
So I finally used the postgres driver for Node instead of pg. Then I had to ‘skipLibCheck’ and it worked like a charm.
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
Hey @Eko sure
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
That was the missing link @Andrew Sherman thank you ! You're the best man I made it work finally Next.js + serverless Lambdas + drizzle-orm in a Turborepo
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
Thank you @Andrew Sherman ! I got this step working, but I'm stuck at linting step with wrong types for drizzle-orm This is the error;
- info Linting and checking validity of types .Failed to compile.

../../node_modules/.pnpm/drizzle-orm@0.25.4_kdjlz5zwvqpzqszfg4d2qbuxze/node_modules/drizzle-orm/db.d-266cc4bc.d.ts:515:15
Type error: Non-abstract class 'PgSelect<TTableName, TSelection, TSelectMode, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'.

513 | interface PgSelect<TTableName extends string | undefined, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>, QueryPromise<SelectResult<TSelection, TSelectMode, TNullabilityMap>[]> {
514 | }
> 515 | declare class PgSelect<TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap> {
| ^
516 | private _prepare;
517 | /**
518 | * Create a prepared statement for this query. This allows
 ELIFECYCLE  Command failed with exit code 1.
- info Linting and checking validity of types .Failed to compile.

../../node_modules/.pnpm/drizzle-orm@0.25.4_kdjlz5zwvqpzqszfg4d2qbuxze/node_modules/drizzle-orm/db.d-266cc4bc.d.ts:515:15
Type error: Non-abstract class 'PgSelect<TTableName, TSelection, TSelectMode, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'.

513 | interface PgSelect<TTableName extends string | undefined, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>, QueryPromise<SelectResult<TSelection, TSelectMode, TNullabilityMap>[]> {
514 | }
> 515 | declare class PgSelect<TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap> {
| ^
516 | private _prepare;
517 | /**
518 | * Create a prepared statement for this query. This allows
 ELIFECYCLE  Command failed with exit code 1.
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
Ok I'm trying this now -> https://github.com/vercel/next.js/pull/48402 It seems they're fixing it
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
I've seen a related question here -> https://github.com/orgs/vercel/discussions/228
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
Use Docker for your deployment: If Vercel supports it, you could use a Docker container for your deployment. This would allow you to set up the environment exactly as you need it, including installing PostgreSQL.

Remember, the core issue here is that libpq is trying to build native bindings and can't find the necessary PostgreSQL development files. Any solution will need to either make those files available, avoid the need for them, or build the bindings in a different environment.

In case you are using pg-native for performance reasons and you are willing to sacrifice some of it for compatibility, you can remove it and use pg alone, which is a pure JS implementation and doesn't require compiling any native code. As long as you don't explicitly require pg-native in your code, pg will work just fine.
Use Docker for your deployment: If Vercel supports it, you could use a Docker container for your deployment. This would allow you to set up the environment exactly as you need it, including installing PostgreSQL.

Remember, the core issue here is that libpq is trying to build native bindings and can't find the necessary PostgreSQL development files. Any solution will need to either make those files available, avoid the need for them, or build the bindings in a different environment.

In case you are using pg-native for performance reasons and you are willing to sacrifice some of it for compatibility, you can remove it and use pg alone, which is a pure JS implementation and doesn't require compiling any native code. As long as you don't explicitly require pg-native in your code, pg will work just fine.
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
Our friend GPT4 told me that;
The error message you're seeing is happening because the libpq library is trying to find the PostgreSQL development files, which it needs to build the native bindings. The issue is that those files aren't present in the Vercel build environment.

Here are a few ways you can solve this:

Prebuild your app before deploying: If possible, you could build your app in an environment where PostgreSQL is installed (such as your local development environment) and then deploy the built files to Vercel. This way, libpq doesn't need to build the bindings during the Vercel deploy process.

Use a PostgreSQL client that doesn't require native bindings: Instead of using a package that requires the PostgreSQL development files, you might consider using a pure JavaScript implementation. An example is pg-promise or node-postgres (pg). These libraries do not require any native bindings, so you won't run into the same issue.

Mock out or avoid using packages that require PostgreSQL in your Vercel deployment: If you're only using PostgreSQL in certain parts of your app, you could consider mocking those parts out or setting your code up to avoid them when running in the Vercel environment. This would likely involve setting up some environment-specific configuration in your code.
The error message you're seeing is happening because the libpq library is trying to find the PostgreSQL development files, which it needs to build the native bindings. The issue is that those files aren't present in the Vercel build environment.

Here are a few ways you can solve this:

Prebuild your app before deploying: If possible, you could build your app in an environment where PostgreSQL is installed (such as your local development environment) and then deploy the built files to Vercel. This way, libpq doesn't need to build the bindings during the Vercel deploy process.

Use a PostgreSQL client that doesn't require native bindings: Instead of using a package that requires the PostgreSQL development files, you might consider using a pure JavaScript implementation. An example is pg-promise or node-postgres (pg). These libraries do not require any native bindings, so you won't run into the same issue.

Mock out or avoid using packages that require PostgreSQL in your Vercel deployment: If you're only using PostgreSQL in certain parts of your app, you could consider mocking those parts out or setting your code up to avoid them when running in the Vercel environment. This would likely involve setting up some environment-specific configuration in your code.
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/12/2023 in #help
Deploying Next.js w/ Drizzle on Vercel with Turborepo
I've had no error in local development. But when trying to deploy to Vercel I've had this error;
.../libpq@1.8.12/node_modules/libpq install: which: no pg_config in (/vercel/path0/node_modules/.pnpm/libpq@1.8.12/node_modules/libpq/node_modules/.bin:/vercel/path0/node_modules/.pnpm/libpq@1.8.12/node_modules/.bin:/vercel/path0/node_modules/.bin:/pnpm7/node_modules/pnpm/dist/node-gyp-bin:/vercel/path0/node_modules/.pnpm/node_modules/.bin:/vercel/path0/node_modules/.bin:/pnpm7/node_modules/.bin:/vercel/.yarn/bin:/vercel/.config/yarn/global/node_modules/.bin:/node18/bin:/ruby27/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
.../libpq@1.8.12/node_modules/libpq install: find: ‘/usr/pg*’: No such file or directory
.../libpq@1.8.12/node_modules/libpq install: gyp: Call to 'which pg_config || find /usr/bin /usr/local/bin /usr/pg* /opt -executable -name pg_config -print -quit' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! configure error
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack Error: `gyp` failed with exit code: 1
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack at ChildProcess.onCpExit (/pnpm7/node_modules/pnpm/dist/node_modules/node-gyp/lib/configure.js:325:16)
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack at ChildProcess.emit (node:events:513:28)
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:291:12)
.../libpq@1.8.12/node_modules/libpq install: which: no pg_config in (/vercel/path0/node_modules/.pnpm/libpq@1.8.12/node_modules/libpq/node_modules/.bin:/vercel/path0/node_modules/.pnpm/libpq@1.8.12/node_modules/.bin:/vercel/path0/node_modules/.bin:/pnpm7/node_modules/pnpm/dist/node-gyp-bin:/vercel/path0/node_modules/.pnpm/node_modules/.bin:/vercel/path0/node_modules/.bin:/pnpm7/node_modules/.bin:/vercel/.yarn/bin:/vercel/.config/yarn/global/node_modules/.bin:/node18/bin:/ruby27/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
.../libpq@1.8.12/node_modules/libpq install: find: ‘/usr/pg*’: No such file or directory
.../libpq@1.8.12/node_modules/libpq install: gyp: Call to 'which pg_config || find /usr/bin /usr/local/bin /usr/pg* /opt -executable -name pg_config -print -quit' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! configure error
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack Error: `gyp` failed with exit code: 1
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack at ChildProcess.onCpExit (/pnpm7/node_modules/pnpm/dist/node_modules/node-gyp/lib/configure.js:325:16)
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack at ChildProcess.emit (node:events:513:28)
.../libpq@1.8.12/node_modules/libpq install: gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:291:12)
21 replies
DTDrizzle Team
Created by sevenwestonroads on 5/7/2023 in #help
The inferred type of '<tableName>' cannot be named without a reference to '.pnpm/zod@3.21.4
Ok I made it work; DISCLAIMER -> I'm using turborepo I uninstalled drizzle-zod globally, but installed it locally in my packages/database (ie. subfolder where my tables, types are defined) ------ But for the createInsertSchema I now got the following error
he inferred type of 'accountsSelectSchema' cannot be named without a reference to '.pnpm/drizzle-orm@0.25.4/node_modules/drizzle-orm/mysql-core'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'accountsSelectSchema' cannot be named without a reference to '.pnpm/drizzle-orm@0.25.4/node_modules/drizzle-orm/pg-core'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'accountsSelectSchema' cannot be named without a reference to '.pnpm/drizzle-orm@0.25.4/node_modules/drizzle-orm/sqlite-core'. This is likely not portable. A type annotation is necessary.ts(2742)
const accountsSelectSchema: ZodObject<Simplify<{ [K in keyof TTable["_"]["columns"]]: MaybeOptional<TTable["_"]["columns"][K], K extends keyof TRefine ? Assume<UnwrapValueOrUpdater<TRefine[K]>, ZodTypeAny> : GetZodType<...>, "select", TNoOptional>; }>, UnknownKeysParam, ZodTypeAny, {
...;
}, {
...;
}>
he inferred type of 'accountsSelectSchema' cannot be named without a reference to '.pnpm/drizzle-orm@0.25.4/node_modules/drizzle-orm/mysql-core'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'accountsSelectSchema' cannot be named without a reference to '.pnpm/drizzle-orm@0.25.4/node_modules/drizzle-orm/pg-core'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'accountsSelectSchema' cannot be named without a reference to '.pnpm/drizzle-orm@0.25.4/node_modules/drizzle-orm/sqlite-core'. This is likely not portable. A type annotation is necessary.ts(2742)
const accountsSelectSchema: ZodObject<Simplify<{ [K in keyof TTable["_"]["columns"]]: MaybeOptional<TTable["_"]["columns"][K], K extends keyof TRefine ? Assume<UnwrapValueOrUpdater<TRefine[K]>, ZodTypeAny> : GetZodType<...>, "select", TNoOptional>; }>, UnknownKeysParam, ZodTypeAny, {
...;
}, {
...;
}>
4 replies
DTDrizzle Team
Created by sevenwestonroads on 5/7/2023 in #help
The inferred type of '<tableName>' cannot be named without a reference to '.pnpm/zod@3.21.4
Here's what's throwing the error; export const accountsInsertSchema = createInsertSchema(accounts); With accounts being a pgTable (defined without error). Here are my versions;
"drizzle-orm": "^0.25.4",
"drizzle-zod": "^0.4.1",
"drizzle-orm": "^0.25.4",
"drizzle-zod": "^0.4.1",
4 replies
DTDrizzle Team
Created by sevenwestonroads on 4/30/2023 in #help
Typesafe floats ?
float does not work in PSQL if I'm not mistaken. I've used this ->
weight: decimal('weight', { precision: 4, scale: 2 })
weight: decimal('weight', { precision: 4, scale: 2 })
But still got the string type
4 replies
DTDrizzle Team
Created by sevenwestonroads on 4/30/2023 in #help
Typesafe floats ?
At the moment - here's what I'm doing: weight: (100).toFixed(2)
4 replies