InferSelectModel does not work with a view

I have a simple view defined as
const qb = new QueryBuilder();
const ordinaryUsersQuery = qb
.select({
id: ordinaryUsers.id,
email: ordinaryUsers.email,
campusId: ordinaryUsers.campusId,
createdAt: ordinaryUsers.createdAt,
lastLoginAt: ordinaryUsers.lastLoginAt,
provider: sql<string>`'ordinary'`.as('auth_provider'),
})
.from(ordinaryUsers);
export const usersView = pgView('users').as(ordinaryUsersQuery);
const qb = new QueryBuilder();
const ordinaryUsersQuery = qb
.select({
id: ordinaryUsers.id,
email: ordinaryUsers.email,
campusId: ordinaryUsers.campusId,
createdAt: ordinaryUsers.createdAt,
lastLoginAt: ordinaryUsers.lastLoginAt,
provider: sql<string>`'ordinary'`.as('auth_provider'),
})
.from(ordinaryUsers);
export const usersView = pgView('users').as(ordinaryUsersQuery);
Trying to infer the model for this view:
export type User = InferSelectModel<typeof usersView>;
export type User = InferSelectModel<typeof usersView>;
errors out:
Type 'PgViewWithSelection<"users", false, { id: PgColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; generated:...' does not satisfy the constraint 'Table<TableConfig<Column<any, object, object>>>'.
Type 'PgView<"users", false, { id: PgColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; generated: undefined; }...' is missing the following properties from type 'Table<TableConfig<Column<any, object, object>>>': $inferSelect, $inferInsert
Type 'PgViewWithSelection<"users", false, { id: PgColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; generated:...' does not satisfy the constraint 'Table<TableConfig<Column<any, object, object>>>'.
Type 'PgView<"users", false, { id: PgColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; generated: undefined; }...' is missing the following properties from type 'Table<TableConfig<Column<any, object, object>>>': $inferSelect, $inferInsert
am i missing something?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server