|
NAMEOpenXPKI::Server::Database::Role::Driver - Moose role that every database driver has to consumeSYNOPSISpackage OpenXPKI::Server::Database::Driver::MyDB2; use Moose; with 'OpenXPKI::Server::Database::Role::SequenceSupport'; with 'OpenXPKI::Server::Database::Role::MergeEmulation'; with 'OpenXPKI::Server::Database::Role::Driver'; # required by OpenXPKI::Server::Database::Role::Driver sub dbi_driver { 'DB2' } # DBI compliant driver name sub dbi_dsn { # DSN string including all parameters. my $self = shift; return sprintf("dbi:%s:dbname=%s", $self->dbi_driver, $self->name, ); } sub dbi_connect_params { {} } # Additional parameters for DBI's connect() sub sqlam_params { { # Parameters for SQL::Abstract::More limit_offset => 'FetchFirst', } } # required by OpenXPKI::Server::Database::Role::SequenceSupport sub nextval_query { # SQL query to retrieve next sequence value my ($self, $seq) = @_; return "VALUES NEXTVAL FOR $seq"; } __PACKAGE__->meta->make_immutable; Then e.g. in your database.yaml: main: type: MyDB2 ... The above code is actually the current driver for IBM DB2 databases. DESCRIPTIONThis Moose role must be consumed by every OpenXPKI database driver. It defines some standard attributes which represent database connection parameters of the same name (not all are required for every DBMS). Furthermore it requires the consuming class to implement certain methods.Transaction isolation levelPlease make sure that the database transaction isolation level is "READ COMMITTED" as OpenXPKI expects this. If your DBMS has another default transaction level please change it in "dbi_on_connect_do".Example for MySQL: sub dbi_on_connect_do { "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED" } Writing an own driverIf you have a DBMS that is not yet supported by OpenXPKI you can write and use a new driver without changing existing code. The only requirement is that there is a DBI driver for your DBMS (look for it on MetaCPAN <https://metacpan.org/search?q=DBD%3A%3A&search_type=modules>).To connect OpenXPKI to your (not yet supported) DBMS follow these steps:
... and implement the methods that these roles require.
ATTRIBUTES
METHODSPlease note that the following methods are implemented in the driver class that consumes this Moose role.dbi_driverReturns the DBI compliant case sensitive driver name (Str).dbi_dsnReturns the DSN that is passed to "connect" in DBI (Str).dbi_connect_paramsReturns optional parameters that are passed to "connect" in DBI (HashRef).dbi_on_connect_doReturns optional commands to be executed after connecting to the database (ArrayRef or Str).sqlam_paramsReturns optional parameters that are passed to "new" in SQL::Abstract::More (HashRef).sequence_create_queryReturns an OpenXPKI::Server::Database::Query object containing the SQL query that creates a new sequence (or a table emulating a sequence, if the driver has got the role OpenXPKI::Server::Database::Role::SequenceEmulation).Parameters:
sequence_drop_queryReturns an OpenXPKI::Server::Database::Query object containing the SQL query that removes a sequence (or a table emulating a sequence, if the driver has got the role OpenXPKI::Server::Database::Role::SequenceEmulation).Parameters:
next_idReturns the next insert id, i.e. the value of the given sequence (Int).Parameters:
merge_queryBuilds a MERGE query (or emulates it by either an INSERT or an UPDATE query) and returns a OpenXPKI::Server::Database::Query object which contains SQL string and bind parameters.Parameters:
Visit the GSP FreeBSD Man Page Interface. |