Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kiranandcode/petrol
Petrol's an OCaml SQL API made to go FAST.
https://github.com/kiranandcode/petrol
dsl ocaml sql typed-dsl
Last synced: 4 days ago
JSON representation
Petrol's an OCaml SQL API made to go FAST.
- Host: GitHub
- URL: https://github.com/kiranandcode/petrol
- Owner: kiranandcode
- License: other
- Created: 2023-01-11T10:52:10.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T03:50:01.000Z (3 months ago)
- Last Synced: 2024-12-16T12:35:46.310Z (11 days ago)
- Topics: dsl, ocaml, sql, typed-dsl
- Language: OCaml
- Homepage: https://kiranandcode.github.io/petrol/petrol/index.html
- Size: 383 KB
- Stars: 114
- Watchers: 5
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Petrol
Petrol is a Free software library that provides a high-level OCaml API
for interacting with SQL databases. The aim of this interface is to
provide a type-safe API to allow developers to define their SQL tables
and queries directly in OCaml, thereby avoiding the impedence mismatch
and fragility that comes with having to directly write SQL code, as is
typical in a normal Caqti-based project.```ocaml
open Petrol
open Petrol.Sqlite3(* define a new schema *)
let schema = StaticSchema.init ()(* declare a table *)
let example_table, Expr.[name; age] =
StaticSchema.declare_table schema ~name:"example"
Schema.[
field "name" ~ty:Type.text;
field "age" ~ty:Type.int
]
```Petrol's DSL allows you to express complex SQL queries as simple OCaml
function compositions:```ocaml
open Petrol.Sqlite3(* create a query *)
let insert_person ~name:n ~age:a db =
Query.insert ~table:example_table
~values:Expr.[
name := s n;
age := i a
]
|> Request.make_zero
|> Petrol.exec db
```See the rest of the documentation at [here](https://kiranandcode.github.io/petrol/petrol/index.html).