Giter Site home page Giter Site logo

dbcaml logo

A database toolkit built on Riot

Quick Start | Documentation | Examples |   

DBCaml is an async database toolkit built on Riot, an actor-model multi-core scheduler for OCaml 5. DBCaml is inspired by Elixirs where the developer can spin up a connection manager and connections the manager takes cares of.

** Note: DBCaml is currently in development and is not ready for production. Only for testing purposes **

type user = {
  name: string;
  id: int;
  some_int64: int64;
  some_int32: int32;
  some_float: float;
  some_bool: bool;
  pet_name: string option;
  pets: string list;
  pets_array: string array;
}
[@@deriving deserialize]

type users = user list [@@deriving deserialize]

(* Start the database connection pool *)
let* db =
  let config =
    Silo_postgres.config
      ~connections:5
      ~connection_string:
        "postgresql://postgres:postgres@localhost:6432/postgres?sslmode=disabled"
  in

  match Silo_postgres.connect ~config with
  | Ok c -> Ok c
  | Error (`Msg e) -> Error e
in

(* Fetch the user and return the user to a variable *)
let* fetched_users =
  Silo_postgres.query
    db
    ~query:
      "select name, id, some_bool, pet_name, some_int64, some_int32, some_float, pets, pets as pets_array from users limit 2"
    ~deserializer:deserialize_users
in

List.iter
  (fun x ->
    Printf.printf
      "Fetching user with id %d:\nName: %s\nSome float: %f\nSome int64: %d\nSome int32: %d\n%s\n Some bool: %b\nPets: %s\nPets array: %s\n\n"
      x.id
      x.name
      x.some_float
      (Int64.to_int x.some_int64)
      (Int32.to_int x.some_int32)
      (match x.pet_name with
      | Some pn -> Printf.sprintf "Pet name: %S" pn
      | None -> "No pet")
      x.some_bool
      (String.concat ", " x.pets)
      (String.concat ", " (Array.to_list x.pets_array)))
  (Option.get fetched_users);

DBCaml aims to offer:

  • Database pooling. Built using Riots lightweight process to spin up a connection pool.

  • Database Agnostic. Support for Postgres, and more to come (MySQL, MariaDB, SQLite).

  • Built in security. With built-in security it allows users to focus on writing queries, without being afraid of security breaches.

  • Cross Platform. DBCaml compiles anywhere!

  • Not an ORM. DBCaml is not an orm, it simply handles the boring stuff you don't want to deal with and allows you to have full insight on what's going on.

Quick Start

opam pin dbcaml.0.0.2 git+https://github.com/dbcaml/dbcaml

After that, you can use any of the examples as a base for your app, and run them:

dune exec X

Important

DBCaml is heavily in development, the content in this repo will change. It's not production ready and will probably have bugs

DBCaml's Projects

dbcaml icon dbcaml

DBCaml is a database library for OCaml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.