Skip to content

Add a mark to finish query #11

@robert-zaremba

Description

@robert-zaremba

Let's say we use comments to group sql queries

Example

-- file user.sql

--- UPDATE QUERIES ---

--name: EmailUpdate
UPDATE users SET email = $1 where user_id = $2

--name: LevelUpdate
UPDATE users SET level = $1 where user_id = $2

---  REPORTS ---

...

In current implementation --- REPORTS--- comment belongs to LevelUpdate query. Problem is when LevelUpdate is not complete and we update the query on the program side. Let's imagine t hat we have the following:

--name: LevelUpdate
UPDATE users SET level = $1 where user_id IN

and in the application:

q := queries.LevelUpdate + fmt.Sprintf(" (%s)", strings.Join(userIDs, ","))

This will fail: ERROR: syntax error at end of input (SQLSTATE 42601) - because queries.LevelUpdate is finishing with a comment. I know that we can bind here the sqlx solution, however this is just a simple example.

We need a phrase to end the query, eg: --end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions