Generic update component using table schema – how to type the table argument?
SOLVED IN BOTTOM COMMENT
I'm attempting a generic update checkbox component where I can pass a type of MySQL (PlanetScale) table, and an associated keyName, and use those params in the db.update() query.
Can anyone guide me on how to type the table argument?
1 Reply
AnyMySqlTable
didn't work as expected
Removing the checkbox for simplicity.
I'm getting a little closer like this:
Error:
If I change .update(args.model)
to .update(schema.users)
the .set() method does not error?
SOLVED: by inspecting the query builder methods, and typing the args to match
This has the unexpected benefit of moving the complexity (and flexibility!) to the caller. For example, instead of defining only one keyName, the function now accepts "values", and can update any number of values!
Also thanks to @ngregrichardson https://discord.com/channels/1043890932593987624/1105287645363441704/1105287645363441704