Seitenanfang

Which ORM for Dancer and MongoDB?

Dieser Post wurde aus meiner alten WordPress-Installation importiert. Sollte es Darstellungsprobleme, falsche Links oder fehlende Bilder geben, bitte einfach hier einen Kommentar hinterlassen. Danke.


I recently started my first Dancer & MongoDB project. MongoDB is my preferred database (at the moment) and Dancer is a great framework, but something is missing: I really prefer using an ORM and didn't find anything for MongoDB which fits my needs.There are quite a lot MongoDB ORMs on CPAN but everyone has at least one big disadvantage, many have more than one. Some can't work with MapResult collections, others have heavy dependencies (I still hope that the MongoDB driver will abandon it's useless Moose depencency).

It turned out that YAWF::Object::MongoDB is great even with Dancer and without YAWF. I created a project module exporting two subs SERVER and DATABASE by default:

package MyProject::DB;

use strict;use warnings;

use Exporter;use Dancer ':syntax';

our @EXPORT=qw(SERVER DATABASE);our @ISA=qw(Exporter);

sub SERVER { return config()->{MongoDB}->{server} || 'localhost';}

sub DATABASE { return config()->{MongoDB}->{database};}

1;

A new section within the project configuration (or environment file) holds the database information:
MongoDB:    server: "localhost"    database: "MyProject"
Every collection class for my project needs a use MyProject::DB; line - and I'm done. Even easier than DBIx::Class ;-)
 

Noch keine Kommentare. Schreib was dazu

Schreib was dazu

Die folgenden HTML-Tags sind erlaubt:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>