Page MenuHomeHexavara Tech

Crema Query Language : Getting Started
Updated 1,675 Days AgoPublic

Version 1 of 2: You are viewing an older version of this document, as it appeared on Oct 13 2019, 8:29 PM.
This document was moved from elsewhere.

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)
Last Author
galang
Last Edited
Oct 13 2019, 8:29 PM

Document Hierarchy

Event Timeline

galang moved this document from Restricted Phriction Wiki DocumentOct 13 2019, 8:29 PM
galang edited the content of this document. (Show Details)Oct 15 2019, 2:47 PM