Skip to content

Conversation

@SunnysideAaron
Copy link

@SunnysideAaron SunnysideAaron commented Jun 24, 2025

This PR is not ready for merging but I'm adding it in case anyone stumbles on it in the future.
#1 should be merged first.

This PR makes adjustments for prepared statements. passing values directly from urls into sql strings is very dangerous.

Left to do on this PR

  • The MongoDB parser does return values but the strings returned need to be adjusted for MongoDBs parameterized queries format. I don't use MongoDB so I'm leaving that bit for others. Though I could take a stab at it if this PR ever gets close to merging.
  • SQLs prepared statements format can be different based on the DB. "?" and "$1" off the top of my head but I'd have to look at the major players like sqlite, mysql, postgres, Microsoft SQL Server, Oracle, etc. Might make sense to have a way to pass that in or change. Since I'm using Postgres that is what I coded for.
  • readme has to be adjusted for example custom operators
customOperators := []rsql.Operator{
    {
        Operator: "=ilike=",
        Formatter: func(key, value string, paramIndex *int) (string, []any) {
            *paramIndex++
            value = strings.ReplaceAll(value, "*", "%")
            return fmt.Sprintf(`%s ILIKE $%d`, key, *paramIndex), []any{value}
        },
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant