Git Product home page Git Product logo

docto's Introduction

docto

Docto is a domain specific language for document-oriented database iteractions in Elixir.

Document

defmodule Sample.Droid do use Docto.Document

field :object, :id # Database specific global document id field :city # Defaults type will be casted automatically field :temp_hi, :integer field :prcp, :float, default: 0.0 field :firmware, :binary # Database specific binary storage field :docs, :document # Another Docto.Document or [{"key", "value"}] | %{"key" => "value"}

validate do required: [:name, :email], format: {:email, ~r/@/}, inclusion: {:age, 18..20} end

end

defmodule Sample.App do import Docto.Query alias Sample.Droid alias Sample.Repo

def keyword_query do Droid. where: w.prcp > 0 or is_nil(w.prcp), select: w Repo.all(query) end

def pipe_query do Weather |> where(city: "Kraków") |> order_by(:temp_lo) |> limit(10) |> Repo.all end end

Data representation

BSON                Elixir
----------        	------
double              0.0
string              "Elixir"
document            [{"key", "value"}] | %{"key" => "value"} (1)
binary              %BSON.Binary{binary: <<42, 43>>, subtype: :generic}
object id           %BSON.ObjectId{value: <<...>>}
boolean             true | false
UTC datetime        %BSON.DateTime{utc: ...}
null                nil
regex               %BSON.Regex{pattern: "..."}
JavaScript          %BSON.JavaScript{code: "..."}
integer             42
symbol              "foo" (2)
min key             :BSON_min
max key             :BSON_max
  1. Since BSON documents are ordered Elixir maps cannot be used to fully represent them. This driver chose to accept both maps and lists of key-value pairs when encoding but will only decode documents to lists. This has the side-effect that it's impossible to discern empty arrays from empty documents. Additionally the driver will accept both atoms and strings for document keys but will only decode to strings.

  2. BSON symbols can only be decoded.

docto's People

Contributors

b00tanik avatar

Watchers

 avatar  avatar

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.