Phriction Knowledge Center - Hexavara Technology Crema Framework Crema Query Language : Getting Started History Version 1 vs 2
Version 1 vs 2
Version 1 vs 2
Content Changes
Content Changes
**Introduction**
Crema Query Language is a high-level SQL dialect that allows to write queries using a standardised SQL-like language. Crema Query is implemented as a parser that translates syntax in that of the target RDBMS. It aims to be developer friendly.
**Example**
Query-ing using regular query strings
```
var regularQuery string
reqularQuery = “SELECT email, name FROM users ORDER BY name DESC”
res := crema.ExecuteQuery(reqularQuery)
```
while using Crema QL
```
var q *crema.Query
q = crema.Select("email", "name").From("users").OrderBy("name").Desc()
res := crema.ExecuteQuery(q.QueryString)
```
**CRUD Interface**
**1. Create Record**
Standard insert query
```
INSERT INTO users(email,name) VALUES('email@to.me' ,'My Name')
```
translated using Crema QL
```
tableName = "users"
col[0] = "email"
col[1] = "name"
val[0] = "email@to.me"
val[1] = "My Name"
q := crema.Insert(tableName).Columns(col).Values(val)
```
to execute the insertion
```
crema.ExecuteQueryRow(tx, q.QueryString)
```
**2, Read Record**
Standard read query
```
SELECT * FROM users
```
translated using Crema QL
```
tableName = "users"
q := crema.Select().All().From(tableName)
```
to execute the query
```
crema.ExecuteQuery(q.QueryString)
```
**3, Update Record**
Standard update query
```
UPDATE users SET name = 'New Name' WHERE email = 'email@to.me'
```
translated using Crema QL
```
tableName := "users"
newValue := "New Name"
email := "email@to.me"
q := crema.Update(tableName).Set().Equal("name", newValue).Where().Equal("email", email)
```
to execute the query
```
crema.ExecuteNonQuery(q.QueryString)
```
**4. Delete Record**
Standard delete query
```
DELETE FROM users WHERE email = 'email@to.me'
```
translated using Crema QL
```
tableName := "users"
email := "email@to.me"
q := crema.Delete().From(tableName).Where().Equal("email", email)
```
to execute the query
```
crema.ExecuteNonQuery(q.QueryString)
```
**Introduction**
Crema Query Language is a high-level SQL dialect that allows to write queries using a standardised SQL-like language. Crema Query is implemented as a parser that translates syntax in that of the target RDBMS. It aims to be developer friendly.
**Example**
Query-ing using regular query strings
```
var regularQuery string
reqularQuery = “SELECT email, name FROM users ORDER BY name DESC”
res := crema.ExecuteQuery(reqularQuery)
```
while using Crema QL
```
var q *crema.Query
q = crema.Select("email", "name").From("users").OrderBy("name").Desc()
res := crema.ExecuteQuery(q.QueryString)
```
**CRUD Interface**
1. [[ http://phabricator.hexavara.com/w/crema/crema_query/create/ | Create ]]
2. [[ http://phabricator.hexavara.com/w/crema/crema_query/read/ | Read ]]
3. [[ http://phabricator.hexavara.com/w/crema/crema_query/update/ | Update ]]
4. [[ http://phabricator.hexavara.com/w/crema/crema_query/delete/ | Delete ]]
**Introduction**
Crema Query Language is a high-level SQL dialect that allows to write queries using a standardised SQL-like language. Crema Query is implemented as a parser that translates syntax in that of the target RDBMS. It aims to be developer friendly.
**Example**
Query-ing using regular query strings
```
var regularQuery string
reqularQuery = “SELECT email, name FROM users ORDER BY name DESC”
res := crema.ExecuteQuery(reqularQuery)
```
while using Crema QL
```
var q *crema.Query
q = crema.Select("email", "name").From("users").OrderBy("name").Desc()
res := crema.ExecuteQuery(q.QueryString)
```
**CRUD Interface**
**1. Create Record**
Standard insert query
```
INSERT INTO users(email,name) VALUES('email@to.me' ,'My Name')
```
translated using Crema QL
```
tableName = "users"
col[0] = "email"
col[1] = "name"
val[0] = "email@to.me"
val[1] = "My Name"
q := crema.Insert(tableName).Columns(col).Values(val)
```
to execute the insertion
```
crema.ExecuteQueryRow(tx, q.QueryString)
```
**2, Read Record**
Standard read query
```
SELECT * FROM users
```
translated using Crema QL
```
tableName = "users"
q := crema.Select().All().From(tableName)
```
to execute the query
```
crema.ExecuteQuery(q.QueryString)
```
**3, Update Record**
Standard update query
```
UPDATE users SET name = 'New Name' WHERE email = 'email@to.me'
```
translated using Crema QL
```
tableName := "users"
newValue := "New Name"
email := "email@to.me"
q := crema.Update(tableName).Set().Equal("name", newValue).Where().Equal("email", email)
```
to execute the query
```
crema.ExecuteNonQuery(q.QueryString)
```
**4. Delete Record**
Standard delete query
```
DELETE FROM users WHERE email = 'email@to.me'
```
translated using Crema QL
```
tableName := "users"
email := "email@to.me"
q := crema.Delete().From(tableName).Where().Equal("email", email)1. [[ http://phabricator.hexavara.com/w/crema/crema_query/create/ | Create ]]
```
to execute the 2. [[ http://phabricator.hexavara.com/w/crema/crema_query
```/read/ | Read ]]
crema.ExecuteNonQ3. [[ http://phabricator.hexavara.com/w/crema/crema_query(q.QueryString)/update/ | Update ]]
```4. [[ http://phabricator.hexavara.com/w/crema/crema_query/delete/ | Delete ]]