InferSelectModel does not work with a view
I have a simple view defined as
Trying to infer the model for this view:
errors out:
am i missing something?
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);
export type User = InferSelectModel<typeof usersView>;
export type User = InferSelectModel<typeof usersView>;
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
0 Replies