Database queries are done using the let statement and query expression.
The query expression includes a filter expression.
type Customer struct {
id int primaryKey
name string
} end
let c = Customer[true] //get all Customer records
let c2 = Customer[1] //query by primary key
let c3 = Customer[name == 'smith'] //query by expression
There are many ways to specify a query.
| Filter | Name | Description | Equivalent SQL |
|---|---|---|---|
| [true] | all | gets all records for that type | select * from Customer |
| [34] | find by primary key | gets the record with the given primary key | select * from Customer where id=34 |
| [name == ‘smith’] | logical expression. | Can use <,<=,>,>=,==,!=. Gets the record(s) that match the given expression | select * from Customer where name='smith’ |
| [name == ‘smith’ and id > 100] | AND expression. | Gets the record(s) that match the given expression | select * from Customer where name='smith’ and id > 100 |
| [name == ‘smith’ or id > 100] | OR expression. | Gets the record(s) that match the given expression | select * from Customer where name='smith’ and id > 100 |
| [not(name == ‘smith’) or id > 100] | NOT expression. | Gets the record(s) that match the given expression | select * from Customer where not name='smith’ and id > 100 |
| [name in [‘smith’,‘chang’,‘gonzalez’]] | IN expression. | Gets the record(s) that match the given expression | select * from Customer where not name in (‘smith’,‘chang’,‘gonzalez’) |
| [name like ‘%smi%'] | LIKE expression. | Gets the record(s) that match the given expression | select * from Customer where name like ‘%smi%’ |
Date functions extract parts of a date.
| Filter | Name | Description | |
|---|---|---|---|
| [orderDate.year() == 2019] | year. | match by year | |
| [orderDate.month() == 1] | month. | match by month | |
| [orderDate.day() == 31] | day. | match by day | |
| [orderDate.hour() == 18] | hour. | match by hour | |
| [orderDate.minute() == 30] | minute. | match by minute | |
| [orderDate.second() == 30] | second. | match by second |