Skip to content

co2-git/maeva

Repository files navigation

maeva

JS models. Database agnostic.

Usage

import * as data from 'maeva';
import mongodb from 'maeva-mongodb';

// Define a model
const players = data.model('players', {
  name: String,
  score: Number,
  isCaptain: Boolean
});

// Use a data connector to connect to a database server
const connector = mongodb('mongodb://localhost');
const connection = data.connect(connector);

// Now you can fire requests to the database server
await data.insertOne(players, {
  name: 'Joe',
  score: 100,
  isCaptain: true
});

// Find first 100 players sorted by score
await data.findMany(players, {
  isCaptain: true,
  name: /jo/,
  score: data.above(0)
}, {sort: 'score', range: 100});

Client/Server architecture

maeva has been developed with the dichotomy client/server in mind. That's why we provide connectors for the two most basic ways a client app would fire queries: HTTP(s) and Web Sockets.

HTTP example

In your server app:

import * as data from 'maeva';
import postgres from 'maeva-postgresql';
import http from 'maeva-http';

const db = data.connect(postgres('pql://mypostgresserver.com'));
data.connect(http.server('http://myserver.com', {connector: db}));

In your client app:

import * as data from 'maeva';
import http from 'maeva-http';

const usersModel = data.model('users', {email: String});
data.connect(http('http://myserver.com'));
const users = await data.findMany(usersModel);

Web Sockets example

In your server app:

import * as data from 'maeva';
import postgres from 'maeva-postgresql';
import sockets from 'maeva-sockets';

const db = data.connect(postgres('pql://mypostgresserver.com'));
data.connect(sockets.server('ws://myserver.com', {connector: db}));

In your client app:

import * as data from 'maeva';
import sockets from 'maeva-sockets';

const usersModel = data.model('users', {email: String});
data.connect(sockets('ws://myserver.com'));
const users = await data.findMany(usersModel);

Connectors

Most popular databases

JavaScript databases

  • maeva-json A json database that lives in memory - with an option to persist data in storage

Client APIs

  • maeva-http A built-in HTTP API you can plug to any maeva connector
  • maeva-sockets A built-in Web Socket API you can plug to any maeva connector

Docs

About

ORM in nodejs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages