Giter Site home page Giter Site logo

mandel's Introduction

NAME

Mandel - Async model layer for MongoDB objects using Mango

VERSION

0.11

SYNOPSIS

package MyModel;
use Mandel;

package MyModel::Cat;
use Mandel::Document;
use Types::Standard 'Str';
field name => ( isa => Str );
field 'type';
belongs_to person => 'MyModel::Person';

package MyModel::Person;
use Mandel::Document;
use Types::Standard 'Int';
field [qw( name )];
field age => ( isa => Int );
has_many cats => 'MyModel::Cat';
has_one favorite_cat => 'MyModel::Cat';

package main;
my $connection = MyModel->connect("mongodb://localhost/my_db");
my $persons = $connection->collection('person');

my $p1 = $persons->create({ name => 'Bruce', age => 30 });
$p1->save(sub {
  my($p1, $err) = @_;
});

$persons->count(sub {
  my($persons, $err, $n_persons) = @_;
});

$persons->all(sub {
  my($persons, $err, $objs) = @_;
  for my $p (@$objs) {
    $p->age(25)->save(sub {});
  }
});

$persons->search({ name => 'Bruce' })->single(sub {
  my($persons, $err, $person) = @_;

  $person->cats(sub {
    my($person, $err, $cats) = @_;
    $_->remove(sub {}) for @$cats;
  });

  $person->remove(sub {
    my($person, $err) = @_;
  });
});

DESCRIPTION

THIS IS ALPHA SOFTWARE! THE API MAY BE CHANGED AT ANY TIME! PLEASE CONTACT ME IF YOU HAVE ANY COMMENTS OR FEEDBACK.

Mandel is an async object-document-mapper. It allows you to work with your MongoDB documents in Perl as objects.

This class binds it all together:

ATTRIBUTES

Mandel inherits all attributes from Mojo::Base and implements the following new ones.

namespaces

The namespaces which will be searched when looking for Types. By default, the (sub)class name of this module.

model_class

Returns Mandel::Model.

storage

An instance of Mango which acts as the database connection. If not provided.

METHODS

Mandel inherits all methods from Mojo::Base and implements the following new ones.

connect

$self = $class->connect(@connect_args);
$clone = $self->connect(@connect_args);

@connect_args will be passed on to "new" in Mango, which again will be set as "storage".

Calling this on an object will return a clone, but with a fresh "storage" object.

all_document_names

@names = $self->all_document_names;

Returns a list of all the documents in the "namespaces".

class_for

$document_class = $self->class_for($name);

Given a document name, find the related class name, ensure that it is loaded (or else die) and return it.

collection

$collection_obj = $self->collection($name);

Returns a Mango::Collection object.

model

$model = $self->model($name);
$self = $self->model($name => \%model_args);
$self = $self->model($name => $model_obj);

Define or returns a Mandel::Model object. Will die unless a model is registered by that name or "class_for" returns a class which has the model() method defined.

initialize

$self->initialize(@names, \%args);
$self->initialize(\%args);

Takes a list of document names. Calls the "initialize" in Mango::Document method on any document given as input. @names default to "all_document_names" unless specified.

%args defaults to empty hash ref, unless specified as input.

The initialize() method will be called like this:

$document_class->initialize($self, \%args);

import

See "SYNOPSIS".

SEE ALSO

Mojolicious, Mango

SOURCE REPOSITORY

http://github.com/jhthorsen/mandel

AUTHOR

Jan Henning Thorsen - [email protected]

Joel Berger - [email protected]

Holger Rupprecht - [email protected]

This project is a fork of MangoModel, created by Joel Berger, [email protected].

COPYRIGHT AND LICENSE

Copyright (C) 2013 by Jan Henning Thorsen

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

mandel's People

Contributors

jberger avatar dsteinbrunner avatar

Watchers

James Cloos 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.