Code Monkey home page Code Monkey logo

Comments (2)

stephenafamo avatar stephenafamo commented on June 11, 2024

Apologies, the docs are wrong.

Both Where and Expr return QueryMods. Expr can be used to group where mods. It comes it handly when using the where mods that were generated for the models.

Both of them can be used to express (A || B ) & (C || D)

Using qm.Where

qm.Where("(a = ? OR b = ?) AND (c = ? OR d = ?)", a, b, c, d),

Using qm.Expr

qm.Expr(
  models.PilotWhere.A.EQ(a),
  qm.Or2(models.PilotWhere.B.EQ(b)),
),
qm.Expr(
  models.PilotWhere.C.EQ(c),
  qm.Or2(models.PilotWhere.D.EQ(d)),
),

from sqlboiler.

iwasherefirst2 avatar iwasherefirst2 commented on June 11, 2024

Thank you for the quick reply and the answer.

One more question about the docs, at the same section, it shows a sequence of conditions like this:

// WHERE IN clause building
WhereIn("(name, age) in ?", "John", 24, "Tim", 33) // Generates: WHERE ("name","age") IN (($1,$2),($3,$4))
WhereIn(fmt.Sprintf("(%s, %s) in ?", models.PilotColumns.Name, models.PilotColumns.Age), "John", 24, "Tim", 33)
AndIn("weight in ?", 84)
AndIn(models.PilotColumns.Weight + " in ?", 84)
OrIn("height in ?", 183, 177, 204)
OrIn(models.PilotColumns.Height + " in ?", 183, 177, 204)

But I guess those conditions have to be wrapped also by qm.Expr ?

What about things like

Select("id", "name") // Select specific columns.
Select(models.PilotColumns.ID, models.PilotColumns.Name)
From("pilots as p") // Specify the FROM table manually, can be useful for doing complex queries.
From(models.TableNames.Pilots + " as p")

or

GroupBy("name")
GroupBy("name like ? DESC, name", "John")
GroupBy(models.PilotColumns.Name)
OrderBy("age, height")
OrderBy(models.PilotColumns.Age, models.PilotColumns.Height)

Having("count(jets) > 2")
Having(fmt.Sprintf("count(%s) > 2", models.TableNames.Jets)

Limit(15)
Offset(5)

How to wrap them? the comment in the code of qm.Expr seems to state, that only WHERE constraints can be used it it,
I guess thies means WHERE A in (..), GEQ, LEQ etc.. but not having/limit/offset/select ?

from sqlboiler.

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.