goqu icon indicating copy to clipboard operation
goqu copied to clipboard

Disabling the quotes to wrap schema/table/column in statements

Open ic2hrmk opened this issue 2 years ago • 0 comments

Hi,

Is there a chance to disable escaping schema, stable, or column names with " because it makes it hard to write a custom statement for the .Select() method?

Let's say, there are two inner joins to the table, and I want to return the results of this inner joins as JSON objects:

query, params, err := goqu.From(goqu.S("piblic").Table("a")).
    Select(
       `json_buil_obj(
           "id", joinedTableA.id,
           "name", joinedTableA.name,
        )`,
       `json_buil_obj(
           "id", joinedTableB.id,
           "name", joinedTableB.name,
        )`
    ).
    Where(...some condition...).
    InnerJoin(..,..).
    InnerJoin(..,..).
    ToSQL()

The SQL statement that would be generated would be invalid because there would be a few places with double escaping like: ""."

My intent is to return the whole response as a JSON object/array later to avoid the complexity of column-to-field matching (I assume that JSON unmarshaling from the response would provide greater flexibility with very little overhead).

Describe the solution you'd like Allow disabling the schema/table/column escaping:

    InnerJoin(..,..).
    NoEscaping(true).
    ToSQL()

Dialect

  • [X] postgres
  • [ ] mysql
  • [ ] sqlite3

ic2hrmk avatar Aug 24 '22 21:08 ic2hrmk