DBIx-QuickORM
view release on metacpan or search on metacpan
hostname $HOSTNAME
Provide a hostname or IP address for database connections
db mydb => sub {
host 'mydb.mydomain.com';
};
Can be nested under db or server.
port $PORT
Provide a port number for database connection.
db mydb => sub {
port 1234;
};
Can be nested under db or server.
socket $SOCKET_PATH
Provide a socket instead of a host+port
db mydb => sub {
socket '/path/to/db.socket';
};
Can be nested under db or server.
user $USERNAME
username $USERNAME
provide a database username
db mydb => sub {
user 'bob';
};
Can be nested under db or server.
pass $PASSWORD
password $PASSWORD
provide a database password
db mydb => sub {
pass 'hunter2'; # Do not store any real passwords in plaintext in code!!!!
};
Can be nested under db or server.
creds sub { return \%CREDS }
Allows you to provide a coderef that will return a hashref with all
the necessary database connection fields.
This is mainly useful if you credentials are in an encrypted YAML or
JSON file and you have a method to decrypt and read it returning it
as a hash.
db mydb => sub {
creds sub { ... };
};
Can be nested under db or server.
connect sub { ... }
connect \&connect
Instead of providing all the other fields, you may specify a coderef
that returns a DBI connection.
IMPORTANT: This function must always return a new DBI connection it
MUST NOT cache it!
sub mydb => sub {
connect sub { ... };
};
Can be nested under db or server.
dsn $DSN
Specify the DSN used to connect to the database. If not provided then
an attempt will be made to construct a DSN from other parameters, if
they are available.
db mydb => sub {
dsn "dbi:Pg:dbname=foo";
};
Can be nested under db or server.
server $NAME => sub { ... }
Used to define a server with multiple databases. This is a way to
avoid re-specifying credentials for each database you connect to.
You can use db('server_name.db_name') to fetch the database.
Basically this allows you to specify any database fields once in the
server, then define any number of databases that inherit them.
Example:
server pg => sub {
host 'pg.myapp.com';
user $USER;
pass $PASS;
attributes { work_well => 1 }
db 'myapp'; # Points at the 'myapp' database on this db server
db 'otherapp'; # Points at the 'otherapp' database on this db server
# You can also override any if a special db needs slight modifications.
db special => sub {
attributes { work_well => 0, work_wrong => 1 };
};
};
orm myapp => sub {
db 'pg.myapp';
...;
};
orm otherapp => sub {
db 'pg.otherapp';
...;
};
Used at the top level. Can contain db plus the same connection
settings a db can contain (driver, dialect, connect, attributes,
creds, dsn, host, port, socket, user, pass).
schema $NAME => sub { ... }
$schema = schema($NAME)
$schema = schema($NAME => sub { ... })
Used to either fetch or define a schema.
When called with only 1 argument it will fetch the schema with the
given name.
When used inside an ORM builder it will set the schema for the ORM
(all ORMs have exactly one schema).
When called with 2 arguments it will define the schema using the
coderef as a builder.
When called in a non-void context it will return the compiled schema,
otherwise it adds it to the ORM class.
# Define the 'foo' schema:
schema foo => sub {
table a => sub { ... };
( run in 1.036 second using v1.01-cache-2.11-cpan-f52f0507bed )