项目作者: statebox

项目描述 :
CQL: Categorical Query Language implementation in Haskell
高级语言: Haskell
项目地址: git://github.com/statebox/cql.git
创建时间: 2018-07-12T20:00:47Z
项目社区:https://github.com/statebox/cql

开源协议:GNU Affero General Public License v3.0

下载


CQL

Build Status
License: AGPL v3

Categorical Query Language (CQL) implementation in Haskell.

About

CQL is a functional query language that allows you to specify data migrations declaratively, in a way that guarantees their correctness.

It is the culmination of years of original mathematical research after the right balance between flexibility and correctness. Its solid grounding in category theory sets it apart from its ad hoc counterparts, and enables the compositional development and analysis of data transformations to a degree previously impossible.

CQL, formerly known as AQL, was developed by Statebox in collaboration with Conexus, who develop the Java version of CQL.

Learn more.

Example

After building, you can use cql to evaluate a .cql file, e.g.

  1. # build it
  2. stack build
  3. # run `cql` on `examples/Employee.cql`
  4. stack exec cql examples/Employee.cql

Here is an example of what a .cql file looks like:

  1. options
  2. program_allow_nontermination_unsafe = true
  3. allow_empty_sorts_unsafe = true
  4. typeside T = literal {
  5. types
  6. string
  7. nat
  8. constants
  9. Al Akin Bob Bo Carl Cork Dan Dunn Math CS : string
  10. zero : nat
  11. functions
  12. succ : nat -> nat
  13. plus : nat, nat -> nat
  14. }
  15. schema S = literal : T {
  16. entities
  17. Employee
  18. Department
  19. foreign_keys
  20. manager : Employee -> Employee
  21. worksIn : Employee -> Department
  22. secretary : Department -> Employee
  23. attributes
  24. first last : Employee -> string
  25. age : Employee -> nat
  26. name : Department -> string
  27. }
  28. instance I = literal : S {
  29. generators
  30. a b : Employee
  31. equations
  32. a.manager = a
  33. a.worksIn.secretary = a
  34. b.manager = a
  35. b.worksIn = a.worksIn
  36. last(b) = Bo
  37. multi_equations
  38. first -> {a Al, b Bob}
  39. }
  40. instance J = literal : S {
  41. generators
  42. a b : Employee
  43. c d : Department
  44. y : nat
  45. equations
  46. a.manager = a
  47. a.worksIn = d
  48. c.secretary = b
  49. b.manager = a
  50. b.worksIn = c
  51. d.secretary = b
  52. first(a) = Al
  53. a.last = Al
  54. d.name = Bob
  55. c.name = Al
  56. age(a) = zero
  57. age(b) = y
  58. options interpret_as_algebra = true
  59. }

Building

The package can be built/tested/installed the following ways.

Stack

Build:

stack build

Test:

stack test

Install:

stack install

Generate docs:

stack haddock cql

Cabal

Generate .cabal file:

hpack

Build:

cabal build

Test:

cabal test

Install:

cabal install

Nix

Build & test:

nix-build

Install in current profile:

nix-env -f . -i

See also default.nix

HTTP API

To launch the APIs, use stack exec cql-http. Then you can send http requests to port 8080, with an CQL specification in the body. The Content-Type of the request needs to be set to text/plain;charset=utf-8

For example, you could try using cURL as follows

  1. curl -X POST \
  2. http://localhost:8080/cql \
  3. -H 'Content-Type: text/plain;charset=utf-8' \
  4. --data-binary "@./examples/Employee.cql"

You can set the following environment variables to customise the behaviour of the endpoint:

  • CQL_ENV: Should be Development or Production. Regulates the verbosity of the console output.

  • PORT: determines on which port the endpoint is exposed

License

Unless explicitly stated otherwise all files in this repository are licensed under the GNU Affero General Public License.

Copyright © 2019 Stichting Statebox.