#Generic helper function for Kysley

2 messages · Page 1 of 1 (latest)

fluid cedar
#

I'm trying to create a function to help me validate related data involved on some sql tests I'll be running with Kysely.
Untyped, my helper function would look like this:

export function defineSqlTestSuite(queryFn, modifierFn, cases)  => { query, modify, cases }

const queryFn = ({ name: string }) => db.selectFrom('foo').where('name', 'eq', name).select('name')

const tests = defineSqlTestSuite(
  queryFn,
  (query) => query.select('rowid'), // query is the return type of queryFn above
  cases: [{ params: { name: 'bar' }, expected: [{ rowid: 1, name: 'bar' }] }] // params is typed based on queryFn first arg, expected is typed based on the ReturnType of the execute method on the ReturnType of the modifierFn
)

I cannot seem to figure out how to type the defineSqlTestSuite function. Maybe it can't be done with Kysely

fluid cedar