Reconstruct Queries from toSQL() data

Hey everyone, I have an interesting use case. I'm trying to figure out if there's a way to reconstruct/run a query from a Query object obtained via query.toSQL(). Something like:
ts
const query = db.select().from(usersTable).limit(1);
const sql: Query = query.toSQL();

// Is there a way to do something like this?
const queryFromSql = db.fromSQL(sql); // or any other approach?
ts
const query = db.select().from(usersTable).limit(1);
const sql: Query = query.toSQL();

// Is there a way to do something like this?
const queryFromSql = db.fromSQL(sql); // or any other approach?
I know this might seem unusual, but I have a specific use case where I need to serialize and later reconstruct queries. Would love to hear if anyone has ideas on how to achieve this or alternative approaches I could explore.
1 Reply
Mario564
Mario5642w ago
Could I get more context about the use case? A simple solution would be to JSON.stringify and then JSON.parse the result of toSQL(), but not sure what your requirements are
Want results from more Discord servers?
Add your server