We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given the following struct
type Person struct { Name string `db:"name"` Age int `db:"age"` } p := Person{ Name: "Jon", Age: 30, }
There doesn't seem to be a quick way to directly select all of the data from a struct:
SELECT 'Jon' AS "name", 30 AS "age"
Similar to the way it is interpreted in Dataset.Insert():
Dataset.Insert()
goqu.From("table").Insert(&p) // INSERT INTO "table" ("name", "age") VALUES ("Jon", 30)
The current behaviour is:
goqu.From().Select(&p) // SELECT "name", "age"
and
goqu.From(&p) // SELECT * FROM "name", "age"
The best way I can come up with currently, is something like this:
goqu.From().Select( goqu.L("?", p.Name).As("name"), goqu.L("?", p.Age).As("age"), ) // SELECT 'Jon' AS "name", 30 AS "age"
I'd like to propose a way to more easily build such a query.
I think there should be a new function, perhaps goqu.V, for explicitly stating that I want to use the value as a literal.
goqu.V
goqu.From().Select( goqu.V("Jon").As("name"), goqu.V(30).As("age"), ) // SELECT 'Jon' AS "name", 30 AS "age" goqu.From().Select(goqu.V(p)) // SELECT 'Jon' AS "name", 30 AS "age" goqu.From().Select(goqu.V(p).As("person")) // SELECT ('Jon', 30) AS "person"
I'm not sure about the interactions with other expressions, or other databases, esp. the tuple syntax. It works in postgres though.
The text was updated successfully, but these errors were encountered:
Added goqu.V for #104
70cbd6a
+* [ADDED] `goqu.V` so values can be used on the LHS of expressions #104
I added this in v8.0.1 #113. It just an alias for goqu.L("?", val). Ill close this once I release the new version.
v8.0.1
goqu.L("?", val)
Sorry, something went wrong.
539a694
251428a
* [ADDED] `goqu.V` so values can be used on the LHS of expressions #104
No branches or pull requests
Given the following struct
There doesn't seem to be a quick way to directly select all of the data from a struct:
Similar to the way it is interpreted in
Dataset.Insert()
:The current behaviour is:
and
The best way I can come up with currently, is something like this:
I'd like to propose a way to more easily build such a query.
I think there should be a new function, perhaps
goqu.V
, for explicitly stating that I want to use the value as a literal.I'm not sure about the interactions with other expressions, or other databases, esp. the tuple syntax. It works in postgres though.
The text was updated successfully, but these errors were encountered: