Use results of a column to pass where conditions elsewhere in the query?

I have a field that stores filters that I parse into the SQL conditions for a where clause. Or at least, that's the goal.

That field is in my views table. Is it possible to pass the result of that field in views into a nested where condition?


export async function getTableData(opts: { db: Db; tableShortId: string; viewShortId: string }) {

    const { db, tableShortId, viewShortId } = opts

    const tableData = await db.query.views.findFirst({
        where: and(eq(views.shortId, viewShortId), eq(views.tableId, tableShortId)),
        columns: {
            shortId: true,
        },
        with: {
            // Get the view for the table
            table: {
                columns: { shortId: true },
                with: {
                    fields: {
                        columns: { shortId: true },
                    },
                    records: {
                                                //! is it possible to filter records by view.jsonColumn after being parsed
                        columns: { shortId: true },
                        with: {
Was this page helpful?