Seifeddine  LARGAT
Seifeddine LARGAT
DTDrizzle Team
Created by Seifeddine LARGAT on 7/17/2024 in #help
Need a review / suggestion please
Hello , i want to store the positions of items depending on the user preferences ( using a sortable list in which he can even move up or down one of the items ) i thought about this solution using transactions and some how two queries. is there anybody free to take look please and thanks in advance 🙏 here is a live example on :
2 replies
DTDrizzle Team
Created by Seifeddine LARGAT on 7/8/2024 in #help
Define shared columns
hello , please i'm trying to create some shared columns definition in able to be used in multiple tables . my file structure : -> database/tables/<table_name>.ts : containing table definition + relations + schemas + types -> database/tables/utils.ts: containing the shared functions + columns definitions -> database/tables/index.ts : export all the tables + utils here is where i define the shared columns : ( database/tables/utils.ts)
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
5 replies
DTDrizzle Team
Created by Seifeddine LARGAT on 6/19/2024 in #help
Derived Values
Hi, Just wanted to know if there is a possible way to create derived values based on another field's value (maybe using customTypes or defaultFn ?)
1 replies