Reputation: 63
Is there easy way to convert SQL string like:
SELECT u.name, u.role
FROM users
WHERE user_id = ?
to any of SQL builders like JOOQ, QueryDsl just to get ability to modify query — add joins, additional "where" clauses, LIMIT-OFFSET?
Upvotes: 4
Views: 853
Reputation: 221360
jOOQ's more recent versions have introduced a parser, which parses arbitrary SQL from all currently supported vendor dialects into the jOOQ expression tree. Once you have that expression tree, you can manipulate it to whatever you want using the VisitListener
SPI.
For jOOQ, there exists a third-party contribution by Gudu Software called SQL 2 jOOQ, which can parse SQL SELECT
statements written in either MySQL or PostgreSQL dialects and generate jOOQ code as output.
Upvotes: 2
Reputation: 11858
Another option, I've used JSQLParser in the past for a project like this. It wasn't very difficult to use.
Upvotes: 5