Beck
Beck
DTDrizzle Team
Created by GermanJablo on 12/31/2024 in #help
`findMany` returns an empty array if the number of rows is +500 approx.
Did you try to run raw SQL query that drizzle generates for you in debug mode? What your db returns if you run that (raw) query?
4 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
@TOSL I tried to use AnyPGColumn in one of the schemas where circular reference occurs, and it solved the issue with TS. Thank you!
17 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
Thanks for clarifying! I’m aware that I can define an application-level relation without specifying references, but I really want a DB-level foreign key to guard my data. Right now, I’m using an application-level relation without an actual FK as a temporary workaround. I’ll definitely try out your AnyPGColumn suggestion, I haven’t used that before, and let you know if it resolves the type inference issue.
17 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
How would reference owner of team without FK to the user? I mean, if you have any ideas of correct implementation please let me know
17 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
17 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
I think you didn’t get the question. I provided you with minimal code to reproduce, it is just made up scenario to show the problem. And helper functions here are not the problem at all. They work just fine. Did you try to run the code solution you provided? It is the same thing and it does not resolve the issue I described. Thank you for trying to help, but you are looking at different things
17 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
What do you mean? I don't have any issues with the config. The issues are in schemas and are related to TS 😦
17 replies
DTDrizzle Team
Created by Beck on 12/28/2024 in #help
TypeScript reference cycles (`ts(7022)` errors)
helper.ts:
import { createId } from '@paralleldrive/cuid2';
import { type NotNull, sql } from 'drizzle-orm';
import { PgColumn, timestamp, varchar } from 'drizzle-orm/pg-core';

export const id = {
id: varchar({ length: 24 }).primaryKey().$defaultFn(createId),
};

export const metadata = {
...id,
createdAt: timestamp({ withTimezone: true, mode: 'string' })
.default(sql`(now() AT TIME ZONE 'utc'::text)`)
.notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' })
.default(sql`(now() AT TIME ZONE 'utc'::text)`)
.notNull()
.$onUpdate(() => sql`(now() AT TIME ZONE 'utc'::text)`),
};

export const ref = <N extends boolean | undefined = false>(
cb: () => PgColumn,
nullable?: N
) => {
const col = varchar({ length: 24 }).references(cb);
return (!nullable ? col.notNull() : col) as N extends true
? typeof col
: NotNull<typeof col>;
};
import { createId } from '@paralleldrive/cuid2';
import { type NotNull, sql } from 'drizzle-orm';
import { PgColumn, timestamp, varchar } from 'drizzle-orm/pg-core';

export const id = {
id: varchar({ length: 24 }).primaryKey().$defaultFn(createId),
};

export const metadata = {
...id,
createdAt: timestamp({ withTimezone: true, mode: 'string' })
.default(sql`(now() AT TIME ZONE 'utc'::text)`)
.notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' })
.default(sql`(now() AT TIME ZONE 'utc'::text)`)
.notNull()
.$onUpdate(() => sql`(now() AT TIME ZONE 'utc'::text)`),
};

export const ref = <N extends boolean | undefined = false>(
cb: () => PgColumn,
nullable?: N
) => {
const col = varchar({ length: 24 }).references(cb);
return (!nullable ? col.notNull() : col) as N extends true
? typeof col
: NotNull<typeof col>;
};
It didn't fit into the limit of the topic so I leave it as a comment
17 replies