Giter Club home page Giter Club logo

Comments (5)

lann avatar lann commented on August 26, 2024

I thought postgresql did support ?, but I see now that its just (?) ODBC that handles that. I have a pretty good idea how to do this.

from squirrel.

lann avatar lann commented on August 26, 2024

This has ended up being a bit more complicated than I originally thought. I'm leaning towards using $? as a sort of pseudo-placeholder to be replaced with $1, $2, etc., along with an explicit PlaceholderFormat setting. Any other suggestions?

from squirrel.

lann avatar lann commented on August 26, 2024

It still needs tests and docs, but the above commit should work like:

sqrl := squirrel.StatementBuilder.PlaceholderFormat(Dollar)
sqrl.Select("*").From("table").Where("x = $?", 5).Where(Eq{"y": 6})
SELECT * FROM table WHERE x = $1 AND y = $2

from squirrel.

th3noname avatar th3noname commented on August 26, 2024

In my opinion it would be better if the placeholder is always just a '?'. That would mean i could do something like:

sqrl := squirrel.StatementBuilder
sqrl.Select("*").From("table").Where("x = ?", 5).Where(Eq{"y": 6})

if db == mysql {
    sql, args, err := sqrl.ToSql().PlaceholderFormat(?)
} else if db == postgres {
    sql, args, err := sqrl.ToSql().PlaceholderFormat(Dollar)
}

from squirrel.

lann avatar lann commented on August 26, 2024

@arpemedia I considered that; the tradeoff is that you would be unable to use a literal "?" in your sql. Might be worth it in the name of standardization I guess.

from squirrel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.