Seifeddine  LARGAT
Seifeddine LARGAT
DTDrizzle Team
Created by Seifeddine LARGAT on 7/17/2024 in #help
Need a review / suggestion please
2 replies
DTDrizzle Team
Created by Seifeddine LARGAT on 7/8/2024 in #help
Define shared columns
thanks for mentioning that🙏🏻
5 replies
DTDrizzle Team
Created by Seifeddine LARGAT on 7/8/2024 in #help
Define shared columns
thanks Raphaël for the quick response , I've just rescanned my tables and i've found a nasty '.'
5 replies
DTDrizzle Team
Created by pvman on 6/2/2024 in #help
Reusable pgTable column helper - losing type : [x: string] instead of user_id
FYI: each table is defined in a single file (i'm using a barrel file to export the hole schema )
6 replies
DTDrizzle Team
Created by pvman on 6/2/2024 in #help
Reusable pgTable column helper - losing type : [x: string] instead of user_id
hello , please i'm trying to do something similar but i'm getting a circular dependency here is where i define the shared columns :
const tokenCols = {
id: serial('id').primaryKey(),
userId: text('user_id')
.notNull()
.references(() => usersTable.id, { onDelete: 'cascade' }),
email: text('email').notNull(),
token: text('token').notNull(),
expiresAt: timestamp('expires_at', { withTimezone: true, mode: 'date' }).notNull()
};

const timestampsCols = {
createdAt: timestamp('created_at', { mode: 'date' }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { mode: 'date' }).$onUpdate(() => new Date())
};

const coordinatesCols = {
latitude: text('latitude'),
longitude: text('longitude')
};

function lower(email: AnyPgColumn): SQL {
return sql`lower(${email})`;
}

export {lower, coordinatesCols, timestampsCols, tokenCols };
const tokenCols = {
id: serial('id').primaryKey(),
userId: text('user_id')
.notNull()
.references(() => usersTable.id, { onDelete: 'cascade' }),
email: text('email').notNull(),
token: text('token').notNull(),
expiresAt: timestamp('expires_at', { withTimezone: true, mode: 'date' }).notNull()
};

const timestampsCols = {
createdAt: timestamp('created_at', { mode: 'date' }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { mode: 'date' }).$onUpdate(() => new Date())
};

const coordinatesCols = {
latitude: text('latitude'),
longitude: text('longitude')
};

function lower(email: AnyPgColumn): SQL {
return sql`lower(${email})`;
}

export {lower, coordinatesCols, timestampsCols, tokenCols };
error:
Cannot access 'timestampsCols' before initialization
Cannot access 'timestampsCols' before initialization
6 replies
DTDrizzle Team
Created by dp on 6/23/2024 in #help
Way to get relations via typeof someSchema.$inferSelect?
hey i found a more precise one on a github discussion (and i'm using it) :
import type { BuildQueryResult, DBQueryConfig, ExtractTablesWithRelations } from 'drizzle-orm';
import type { Exact } from 'type-fest';// <-- you must install type-fest
import * as schema from '../secure/db/schemas';
type TSchema = ExtractTablesWithRelations<typeof schema>;

export type QueryConfig<TableName extends keyof TSchema> = DBQueryConfig<
'one' | 'many',
boolean,
TSchema,
TSchema[TableName]
>;

export type InferQueryModel<
TableName extends keyof TSchema,
QBConfig extends Exact<QueryConfig<TableName>, QBConfig> = {} // <-- notice Exact here
> = BuildQueryResult<TSchema, TSchema[TableName], QBConfig>;
import type { BuildQueryResult, DBQueryConfig, ExtractTablesWithRelations } from 'drizzle-orm';
import type { Exact } from 'type-fest';// <-- you must install type-fest
import * as schema from '../secure/db/schemas';
type TSchema = ExtractTablesWithRelations<typeof schema>;

export type QueryConfig<TableName extends keyof TSchema> = DBQueryConfig<
'one' | 'many',
boolean,
TSchema,
TSchema[TableName]
>;

export type InferQueryModel<
TableName extends keyof TSchema,
QBConfig extends Exact<QueryConfig<TableName>, QBConfig> = {} // <-- notice Exact here
> = BuildQueryResult<TSchema, TSchema[TableName], QBConfig>;
4 replies
DTDrizzle Team
Created by Nicolas on 10/9/2023 in #help
Null fields not working as expected
Hi , i'm having the same problem did you found a solution
2 replies