(
isa => "Str",
is => "rw",
);
----
my $homer = Person->new(
name => "Homer Simpson",
);
----
create a
directory
----
use KiokuDB;
my $dir = KiokuDB->connect($dsn);
----
store it
----
# generate UUID
my $id = $dir->store($homer);
----
# specify id = 'homer'
$dir->store( homer => $homer );
----
fetch it
----
my $homer = $dir->lookup($id);
----
named
objects
----
why?
----
relational
algebra
----
tuples
----
fixed
schema
----
no
encapsulation
----
no
identity
----
SELECT *
FROM objects
WHERE id IN (
SELECT DISTINCT id
...
);
----
objects
----
polymorphism
----
graphs
----
inheritence
----
roles
----
encapsulation
----
objects
!=
tuples
----
collections
!=
relations
----
ORMs do
a subset
of OO
----
“it's
just
data”
----
bullshit
----
why
translate?
----
store
objects
natively
----
KiokuDB
!=
storage
----
KiokuDB
=
frontend
----
where does
my data go?
----
Berkeley DB
----
Directory::Transactional
----
DBI
(blob columns)
----
CouchDB
----
Amazon
SimpleDB
----
Persevere?
----
MongoDB?
----
groonga?
----
RDF?
----
XML?
----
“document
oriented
database”
----
structures
----
references
----
{
"id" : "homer",
"class" : "Employee",
"name" : "Homer Simpson",
"spouse" : "marge", // ref
"job" : "Safety Inspector"
}
----
{
"id" : "marge",
"class" : "Person",
"name" : "Marge Simpson",
"spouse" : "homer" // ref
}
----
object
=
document
----
no
schema
----
simple
----
RAM
↓
Storage
----
not easy
in Perl
----
too many
options
----
requires
guesswork
----
transparent
persistence
----
holy
grail
----
☹
----
2006
----
Moose
obsoletes
guesswork
----
MOP
----
introspection
----
no magic
policy
----
not always
transparent
----
generally
transparent
enough
----
what can
it do?
----
what
Perl
does
----
package Person;
has spouse => (
isa => "Person",
is => "rw",
weak_ref => 1,
);
----
my $marge = $homer->spouse
----
refaddr($homer->spouse->spouse)
==
refaddr($homer)
----
weak
refs
----
must be
referenced
by *something*
----
my $scope = $dir->new_scope;
----
keeps
objects
alive
----
relationships
----
blog
----
post
has one
author
----
author
has many
posts
----
package Author;
use Moose;
use KiokuDB::Util qw(set);
has name => (
is => 'ro',
isa => 'Str',
required => 1,
);
has posts => (
is => 'ro',
isa => 'KiokuDB::Set',
default => sub { set() },
);
----
package Post;
use Moose;
has [qw/title content/] => (
is => 'ro',
isa => 'Str',
);
has author => (
is => 'ro',
isa => 'Author',
weak_ref => 1,
required => 1,
);
----
sub Author::new_post {
my ($self, @args) = @_;
my $post = Post->new(
author => $self, @args
);
$self->posts->insert( $post );
return $post;
}
----
my $jrockway = Author->new(
name => 'jrockway',
);
----
my $id = $dir->insert( $jrockway );
----
my $post = $jrockway->new_post(
title => 'Hello, world',
content => 'OH HAI',
);
----
$dir->insert($post);
$dir->update($jrockway);
----
$dir->store($jrockway);
----
my $jrockway = $dir->lookup($id);
----
use YAML::XS qw(Dump);
print Dump([ $jrockway->posts->members ]);
----
you
know
this
----
just
Perl
----
ACID
----
$dir->txn_do(sub {
my $obj = $dir->lookup($id);
$obj->foo("bar");
$dir->update($obj);
});
----
$dir->txn_do(
scope => 1,
body => sub { ... },
);
----
ACID
Backends
----
Berkeley DB
DBI
CouchDB
Hash
----
no
ACID?
----
noop
----
*always*
txn_do
----
faster
----
safer
----
non
Moose
object?
----
KiokuDB::TypeMap
----
default
typemap
----
DateTime
----
URI
----
Path::Class
----
Authen::Passphrase
----
Tie::RefHash
----
everything
else?
----
KiokuDB::TypeMap::Entry
----
KiokuDB::TypeMap::Entry::Callback->new(
collapse => sub { ... },
expand => sub { ... },
);
----
KiokuDB::TypeMap::Entry::Callback->new(
collapse => "as_string",
expand => "new",
);
----
KiokuDB::TypeMap::Entry::Naive->new,
----
KiokuDB::TypeMap::Entry::Storable->new,
----
value
types
----
intrinsic
----
no
ID
----
{
class => "Person",
birthday => {
class => "DateTime",
data => ...,
},
}
----
KiokuDB::TypeMap::Entry::MOP
----
hinting
roles
----
ID
----
package Person;
with qw(KiokuDB::Role::ID);
sub kiokudb_object_id {
return $self->name;
}
----
Immutable
----
package Never::Changes;
use Moose;
with qw(KiokuDB::Role::Immutable);
----
Intrinsic
----
package Simple::Value;
use Moose;
with qw(KiokuDB::Role::Intrinsic);
----
attribute
traits
----
has spouse => (
traits => [qw(KiokuDB::Lazy)],
...,
);
----
has cached => (
traits => [qw(KiokuDB::DoNotSerialize)],
lazy_build => 1,
....
);
----
KiokuDB->connect(
$dsn
allow_class_builders => 1,
);
----
extra
default
entries
----
Class::Accessor
----
Object::Tiny
----
Object::InsideOut
----
internals
----
KiokuDB::Collapser
----
@objects
↓
@entries
----
entry?
----
simple
data
----
simple
like JSON
----
no
cycles
----
refs
by ID
----
no funny
data types
----
KiokuDB::Linker
----
@entries
↓
@objects
----
is ID
live?
----
load
entry
----
inflate
----
repeat
----
KiokuDB::Backend
----
multiple
drivers
----
roles for
features
----
easy to
implement
----
start
small
----
roles
----
KiokuDB::Serializer
----
JSON
----
(JSPON)
----
YAML
----
Storable
----
how does
it perform?
----
quite
well
----
fast
backends
----
BDB
----
DBI
----
frontend
----
4000
inflations/sec
----
same as
ORMs
----
not
optimized
----
XS
live
objects
----
Moose::XS
----
querying
----
how to
index?
----
⒈
----
Perl
space
----
respects
encapsulation
----
DBI
----
search
columns
----
my $dir = KiokuDB−>connect(
"dbi:SQLite:dbname=foo",
columns => [
name => {
data_type => "varchar",
is_nullable => 1, # probably important
},
],
);
----
columns => [
age => {
data_type => "integer",
extract => sub {
my $obj = shift;
( DateTime->now - $obj->birthday )->years
},
},
],
----
my $i = $dir->search({ age => 50 });
----
Data:::Stream::Bulk
----
while ( my $chunk = $i->next ) {
for my $obj (@$i){
...
}
}
----
Search::GIN
----
stolen
from
Postgres
----
big
plans
----
not
ready
----
but
usable
----
BDB
DBI
----
⒉
----
backend
----
e.g.
CouchDB
views
----
breaks
encapsulation
----
opt in
----
KiokuX::User
----
precanned
user object
----
Authen::Passphrase
----
KiokuDB::Role::ID
----
KiokuX::Model
----
simple
wrapper
----
organize
helper
methods
----
Catalyst::Model::KiokuDB
----
automatic
scope
----
leak
detection
----
authentication
----
CLI
----
kioku help
----
kioku dump
----
kioku load
----
kioku edit
----
kioku fsck
----
kioku gc
----
--dsn bdb:dir=root/db
----
--verbose
----
kioku help dump
----
KiokuDB
at II
----
several
apps
----
old website
converted
to wiki
----
changelog
----
linked list
----
change
objects
----
import
----
edit
----
approve
----
reject
----
revert
----
roles
----
CREATE TABLE changes (
... FAIL
----
too polymorphic
for tuples
----
native
object
storage
----
clean
flexible
model
----
no
encoding
required
----
KiokuDB::Role::ID::Content
----
ID is
SHA-1
----
tutorial
video
site
----
youtube
mashup
----
tutorial
sets
----
social
graph
----
hierchical
tags
----
if you can
do it in
memory…
----
easier
than
SQL
----
prior
art?
----
Tangram
----
Pixie
----
DBM::Deep
----
Moose
is key
----
only
transparent
enough
----
no magic
----
safe
----
predictable
----
but still
easy & fun
----
Other
languages
----
AllegroCache
----
Elephant
----
Conclusion
----
KiokuDB
----
respects
your
objects
----
transparent
but
predictable
----
no
magic
----
native
object
storage
----
goodbye,
relational
----
compromise
----
less
translation
----
less
code
----
simpler
code
----
pie in
the sky?
----
not
vaporware
----
heavily
tested
----
somewhat
documented
----
used in
production
----
the
future
----
persistence
metaclass
----
$obj->id;
$obj->name("bar");
$obj->update;
----
more
collection
APIs
----
transaction
aware
objects
----
joint effort
with DBIC
----
kiokudb.yml
----
data
versioning
----
change
your class
----
upgrade
your data
----
better
Set
implementation
----
scalable
set operations
----
XS
acceleration
----
Search::GIN
overhaul
----
proper
meta
model
----
index
meta
object
----
cleaner
extraction
----
query time
extraction
----
transitive
closures
----
sorting
----
set
operations
----
aggregation?
maybe…
----
plagiarize
PostgreSQL
----
no
query
language
----
query
AST
----
compile
----
low
level
AST
----
scan
----
sort
----
filter
----
join
----
query
planner
----
optimized
query
plan
----
execution
AST
----
index
scan
----
table
scan
----
external
sort
----
in memory
sort
----
multiple
backends
----
BDB
----
SQL
----
SimpleDB
----
incremental
----
start
small
----
lots of
room for
optimizations
----
interesting
queries
----
graphs
----
HALP!
----
KiokuDB::Tutorial
----
http://www.iinteractive.com/kiokudb/
----
#kiokudb
#moose
(irc.perl.org)
----
nothingmuch@woobling.org
----
Thank You
]]>