-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
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
Use own struct for dest #189
Comments
Nice Job! |
Yeah, for complex(nested) structs, |
Is there any way to use Jet without its query builder? I just need it for QRM |
I have the following
My target struct:
but I am unable to unwrap the |
From the raw statements wiki:
So, you can't use SELECT user.username as "user.username",
user.first_name as "user.first_name",
....
FROM user |
The issue is permissions. They are not mapped. |
Alias should be just SELECT article_edit as "permission.editArticle" -- permission not permissions or user.permissions |
Also how to use Also how zero-values are handled for |
Check FAQ for dynamic projection list and condition. The same approach can be used for |
I am trying to use
but it adds extra |
There is no need to wrap the parameter with if q != "" {
has = `article.title LIKE $s`
args["$s"] = "%" + q + "%"
} |
Just to ensure let me ask something an example of what I am doing:
as far as I know MySQL doesn't support named arguments for QueryContext |
Yes, it is sql-injection safe in regard to passed arguments, but when you are using raw sql with string concatenation there are other ways to introduce sql-injection. |
Hi
but cannot import |
Use |
Sorry to ask so many questions. I need to add order clause dynamically.
the SQL result is I have aliased the article so I cannot use simply |
What does AArticle := Article.FromSchema("a") // use different schema(postgres) or database(mysql)
AArticle := Article.As("a_article") // or alias table, but without .
// separate clause constructions from main statement
var orderBy []OrderByClause
for _, column := range AArticle.AllColumns {
...
orderBy = append(orderBy, column.ASC())
...
}
stmt := SELECT(
AArticle.AllColumns,
).FROM(
AArticle,
).ORDER_BY(
orderBy...,
)
|
It didn't work,
|
Ok, so aTitle := Article.Title.From(a) Check the wiki - https://github.com/go-jet/jet/wiki/Subquery |
Yes but how to do that dynamically for all fields |
Aha, I see what you mean. If you iterate columns from var orderBy []OrderByClause
for _, column := range Article.AllColumns {
if columnNameToOrderWith == column.Name() {
exportedColumn := StringColumn(column.TableName() + "." + column.Name()).From(a)
if sort == "ASC" {
orderBy = append(orderBy, exportedColumn.ASC())
}
...
}
...
} |
Hi
Is it possible to use my own struct as the dest to
stmt.Query(db, &dest)
?Currently as the dest is different than my domain struct, I have to copy all dest's fields to my own struct(domain struct) and this isn't performant.
Like:
Currently is:
The text was updated successfully, but these errors were encountered: