Skip to content

Commit 7995513

Browse files
authored
Update querybuilder.md
1 parent 96e29e8 commit 7995513

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/src/querybuilder.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CurrentModule = Wasabi.QueryBuilder
55
# QueryBuilder
66

77
You can use QueryBuilder to create and execute a query in a simple and fast way.
8-
```
8+
```julia
99
using Wasabi
1010
using SQLite
1111

@@ -25,7 +25,7 @@ QueryBuilder supports select, join, where, limit, offset, group by and order by.
2525

2626
Select can be expressed as vector of symbols or using SelectExpr object. If no arguments are passed to select then all fields of the model are selected. You can also use alias and select function like count, sum, avg and so on.
2727

28-
```
28+
```julia
2929
QueryBuilder.from(User) |> QueryBuilder.select() # Select all fields from user model
3030
QueryBuilder.from(User) |> QueryBuilder.select([:id, :name]) # SELECT user_alias.id, user_alias.name FROM user user_alias
3131
QueryBuilder.from(User) |> QueryBuilder.select(User, :id, :total, :count) # SELECT COUNT(user_alias.id) AS total FROM user user_alias
@@ -35,15 +35,15 @@ Join are expressed using source, target, type (inner, outer ...), on, select.
3535
Here's an example to join User with UserProfile using an INNER JOIN and selecting the "bio" column from UserProfile .
3636

3737

38-
```
38+
```julia
3939
query = QueryBuilder.from(User) |> QueryBuilder.select() |> QueryBuilder.join(User, UserProfile, :inner, (:id, :user_id), [:bio])
4040

4141
# SELECT user.id, user.name, user_profile.bio FROM "user" user INNER JOIN "user_profile" user_profile ON user.id = user_profile.user_id
4242
```
4343

4444
Where conditions are expressed as Julia Expr object where you can nest and/or conditions. The condition needs to be expressed as (Model, fieldname, function, params).
4545

46-
```
46+
```julia
4747
query = QueryBuilder.from(User) |> QueryBuilder.select() |> QueryBuilder.where(:(or, (User, name, like, "%mattia%"), (User, id, in, [1, 2, 3]))) |> QueryBuilder.limit(1)
4848
sql, params = QueryBuilder.build(query)
4949

@@ -57,4 +57,4 @@ Modules = [Wasabi.QueryBuilder]
5757

5858
```@autodocs
5959
Modules = [Wasabi.QueryBuilder]
60-
```
60+
```

0 commit comments

Comments
 (0)