Query

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

Query Expressions

There are many ways to specify a query.

FilterNameDescriptionEquivalent SQL
[true]allgets all records for that typeselect * from Customer
[34]find by primary keygets the record with the given primary keyselect * from Customer where id=34
[name == ‘smith’]logical expression.Can use <,<=,>,>=,==,!=. Gets the record(s) that match the given expressionselect * from Customer where name='smith’
[name == ‘smith’ and id > 100]AND expression.Gets the record(s) that match the given expressionselect * from Customer where name='smith’ and id > 100
[name == ‘smith’ or id > 100]OR expression.Gets the record(s) that match the given expressionselect * from Customer where name='smith’ and id > 100
[not(name == ‘smith’) or id > 100]NOT expression.Gets the record(s) that match the given expressionselect * from Customer where not name='smith’ and id > 100
[name in [‘smith’,‘chang’,‘gonzalez’]]IN expression.Gets the record(s) that match the given expressionselect * from Customer where not name in (‘smith’,‘chang’,‘gonzalez’)
[name like ‘%smi%']LIKE expression.Gets the record(s) that match the given expressionselect * from Customer where name like ‘%smi%’

Date Functions

Date functions extract parts of a date.

FilterNameDescription
[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