sukria / coat-persistent Goto Github PK
View Code? Open in Web Editor NEWLightweight and portable database interface (ORM) for Perl based on Ruby's ActiveRecord API
License: GNU General Public License v2.0
Lightweight and portable database interface (ORM) for Perl based on Ruby's ActiveRecord API
License: GNU General Public License v2.0
A method save_without_validate would be welcome to allow a bypass of the validate method.
The following code is buggy:
$obj->save
$obj->delete
$obj->save
Once deleted, the row corresponding to the object is dropped from the database, but C::P does not change the internal state of the object. Hence, the next save call will fail, because it thinks the entry exists in the DB and will try t run an UPDATE query on a non-existent field.
The state should be changed when delete is called (CP_ENTRY_NEW), then a new save call will trigger a INSERT query.
Currently, only one kind of per-attribute finder is supported: find_by_ATTR, they are statically created in the namespace of the class.
ActiveRecord chose to use an AUTOLOAD system to create them on the fly, this allow any finder to be possible, like
Class->find_by_attr1_and_attr2(1, 2);
Class->find_by_attr1_or_attr2(1, 2);
We could do the same as ActiveRecord does and once a finder is called, register it in the namespace.
When more than one model share somt common attrbutes and filters, it's convenient to factor them in a common ancestor, like the following:
package WithDate;
use Coat::Persistent;
has_p 'created_at' => (
isa => 'Class::Date',
store_as => 'DateTime',
);
before save => sub {
my ($self) = @_;
$self->created_at(time) unless $self->created_at;
};
And then, others model can 'extends' WithDate. That works, but something is a bit dirty: WithDate does not map a real table in the database, so it should be marked as a "virtual" model.
My idea is that a virtual model in Coat::Persistent is actually a Role.
packahe WithDate;
use Coat::Persistent::Virtual;
....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.