PQL::Cache also runs on Android without any change, compile or installation.
Just copy the module!
Perl PQL::Cache
Donnerstag, 8. Januar 2015
Mittwoch, 17. Dezember 2014
Info
Hello all,
I have developed an object in memory cache PQL::Cache that can be used like a SQL database. Question is, how API should be defined. My suggestion, similary to DBIx::class:
The $cache may be dumped using Data::Dumper and reloaded, if stored objects can be dumped.
Class is already up and running for data rows as hashes. Possibly we can find a name for this package in DBIx:: namespace.
Is now available at https://metacpan.org/pod/PQL::Cache
(what => 'all',
from => 'person',
where =>
[ or => [ prename => 'Ralf', # scalar: eq (string)
[ gender => 'male'],
surname => [ qw (Peine Conway)], # ArrayRef: In a list
perl_level => { like => 'CPAN.*' }, # HashRef: operator
perl_years => { '>' => 20 }, # its a numerical field
birth => { ge => '1960' }, # its a string field
birth => sub { $_ ge '1960' }, # sub ref: for value
data => sub { $_->{birth} ge '1960' }, # for hash
obj => sub { $_->get_birth() ge '1960' }, # for object
obj => sub { $_->get_city()->get_postcode() eq '4630'},
]
);
For "like" you can use full standard perl regexes.
Any comments?
('person', {
keys => ['ID'],
columns => [prename => surname => birth => gender =>
'perl_level']
});
ID => $person_id++,
prename => 'Ralf',
surname => 'Peine',
gender => 'male',
birth => '1965-12-29',
location => 1, # cannot be searched!
perl_level => 'CPAN',
});
$cache->update_index('person', $read_person);
(what => 'all',
from => 'person',
where => [prename => 'FORREST L.']
);
I have developed an object in memory cache PQL::Cache that can be used like a SQL database. Question is, how API should be defined. My suggestion, similary to DBIx::class:
The $cache may be dumped using Data::Dumper and reloaded, if stored objects can be dumped.
Class is already up and running for data rows as hashes. Possibly we can find a name for this package in DBIx:: namespace.
Is now available at https://metacpan.org/pod/PQL::Cache
Select
my $result = $cache->select(what => 'all',
from => 'person',
where =>
[ or => [ prename => 'Ralf', # scalar: eq (string)
[ gender => 'male'],
surname => [ qw (Peine Conway)], # ArrayRef: In a list
perl_level => { like => 'CPAN.*' }, # HashRef: operator
perl_years => { '>' => 20 }, # its a numerical field
birth => { ge => '1960' }, # its a string field
birth => sub { $_ ge '1960' }, # sub ref: for value
data => sub { $_->{birth} ge '1960' }, # for hash
obj => sub { $_->get_birth() ge '1960' }, # for object
obj => sub { $_->get_city()->get_postcode() eq '4630'},
]
);
For "like" you can use full standard perl regexes.
Any comments?
Defining tables
$cache->set_table_definition('person', {
keys => ['ID'],
columns => [prename => surname => birth => gender =>
'perl_level']
});
Insert data
$cache->insert(person => {ID => $person_id++,
prename => 'Ralf',
surname => 'Peine',
gender => 'male',
birth => '1965-12-29',
location => 1, # cannot be searched!
perl_level => 'CPAN',
});
Update Index
Update of values is not needed, because objects are direct stored in cache.$cache->update_index('person', $read_person);
Delete
my $deleted_row_count = $cache->delete(what => 'all',
from => 'person',
where => [prename => 'FORREST L.']
);
Abonnieren
Posts (Atom)