go-jet / jet

Type safe SQL builder with code generation and automatic query result data mapping
Apache License 2.0
2.52k stars 118 forks source link

How to insert comment or fragment in sql? #244

Open canuran opened 1 year ago

canuran commented 1 year ago

Such as select name from user /* shard_id=1 */ where name like 'can%', the shard_id comment is to tell the database proxy how to route to the sharded database.

Suggest: SELECT(User.Name).FROM(User).FRAG(FRAG("/* shard_id=1 */").BeforeWhere()).WHERE(...)

go-jet commented 1 year ago

Hi @canuran Can you use optimizer hints instead?

canuran commented 1 year ago

Hi @canuran Can you use optimizer hints instead?

It seems impossible, optimizer_hints can only be used for mysql and the format is fixed, not suitable for prompting db proxy.

houten11 commented 1 year ago

What database proxy are you using? Does a comment have to appear at a specific position inside the statement?