matheus
matheus
DTDrizzle Team
Created by matheus on 10/14/2024 in #help
Error: ... not assignable to parameter of type SelectedFields
I am trying to build a wrapper around drizzle select and this is being hard to achieve. What do I want? I want to create a wrapper that receives a where clause and SelectedFields, but I want the type-safety in order to suggest only valid columns to the user. I have something like this:
get<TWhere>(
where: SQL<TWhere>,
select?: Record<keyof typeof schema.subAccountDetail.$inferSelect, unknown>
) {
return this.db
.select(select)
.from(schema.subAccountDetail)
.where(where);
}
get<TWhere>(
where: SQL<TWhere>,
select?: Record<keyof typeof schema.subAccountDetail.$inferSelect, unknown>
) {
return this.db
.select(select)
.from(schema.subAccountDetail)
.where(where);
}
But this is getting me to this error:
Diagnostics:
1. Argument of type 'Record<"id" | "description" | "createdAt" | "updatedAt" | "deletedAt" | "dueDate" | "value" | "externalCreatedBy" | "externalChangedBy" | "originalValue" | "idPerfil" | "idPerfilChangedBy" | "idAccountDetail" | "idSubAccount", unknown>' is not assignable to parameter of type 'SelectedFields'.
Property 'id' is incompatible with index signature.
Type 'unknown' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'. [2345]
Diagnostics:
1. Argument of type 'Record<"id" | "description" | "createdAt" | "updatedAt" | "deletedAt" | "dueDate" | "value" | "externalCreatedBy" | "externalChangedBy" | "originalValue" | "idPerfil" | "idPerfilChangedBy" | "idAccountDetail" | "idSubAccount", unknown>' is not assignable to parameter of type 'SelectedFields'.
Property 'id' is incompatible with index signature.
Type 'unknown' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'. [2345]
If I change from unknown to any, everything works fine. What I really want, is to use $inferSelect type so the method becomes type-safe with selects columns. How can I do that?
1 replies
DTDrizzle Team
Created by matheus on 7/26/2024 in #help
How can I reset migrations timestamp
I am using drizzle in one of my projects and somehow the timestamp of migrations were wrong. Trying to fix it, I edited, by hand, the timestamp value in meta/_journal.json, increasing the timestamp value present in when key. The value I put there is far in the future, and because of that, every new migration that I create is not running due to that inconsistency. So my question is: Can I fix it? How? My meta/_journal.json looks like this:
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1714512333166,
"tag": "0000_pale_bushwacker",
"breakpoints": true
},
{
"idx": 0,
"version": "5",
"when": 1814512333166,
"tag": "0001_insert_accounts_subaccounts",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1915460163263,
"tag": "0001_square_nighthawk",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 2015641951701,
"tag": "0002_light_blonde_phantom",
"breakpoints": true
},
{
"idx": 3,
"version": "5",
"when": 2115641951701,
"tag": "0003_closed_vision",
"breakpoints": true
},
{
"idx": 4,
"version": "5",
"when": 1721225335701,
"tag": "0004_vengeful_wildside",
"breakpoints": true
},
{
"idx": 5,
"version": "5",
"when": 1721931317327,
"tag": "0005_overjoyed_marvel_apes",
"breakpoints": true
}
]
}
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1714512333166,
"tag": "0000_pale_bushwacker",
"breakpoints": true
},
{
"idx": 0,
"version": "5",
"when": 1814512333166,
"tag": "0001_insert_accounts_subaccounts",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1915460163263,
"tag": "0001_square_nighthawk",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 2015641951701,
"tag": "0002_light_blonde_phantom",
"breakpoints": true
},
{
"idx": 3,
"version": "5",
"when": 2115641951701,
"tag": "0003_closed_vision",
"breakpoints": true
},
{
"idx": 4,
"version": "5",
"when": 1721225335701,
"tag": "0004_vengeful_wildside",
"breakpoints": true
},
{
"idx": 5,
"version": "5",
"when": 1721931317327,
"tag": "0005_overjoyed_marvel_apes",
"breakpoints": true
}
]
}
2 replies