Skip to content
Browse files

Add simple implementation of Driver interface for Akiban Server.

  • Loading branch information...
1 parent 16e0692 commit aba84302009cb3473f40b9f4b0d6c84d3d4ebe63 @posulliv committed
Showing with 70 additions and 0 deletions.
  1. +70 −0 lib/Doctrine/DBAL/Driver/AkibanSrv/Driver.php
View
70 lib/Doctrine/DBAL/Driver/AkibanSrv/Driver.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Doctrine\DBAL\Driver\AkibanSrv;
+
+use Doctrine\DBAL\Platforms;
+
+/**
+ * Driver that connects to Akiban Server through pgsql.
+ *
+ * @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
+ * @since 2.3
+ */
+class Driver implements \Doctrine\DBAL\Driver
+{
+ /**
+ * Attempts to connect to the database and returns a driver connection on success.
+ *
+ * @return \Doctrine\DBAL\Driver\Connection
+ */
+ public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
+ {
+ return new AkibanSrvConnection(
+ $username,
+ $password,
+ $this->_constructDsn($params)
+ );
+ }
+
+ /**
+ * Constructs the Akiban Server DSN.
+ *
+ * @return string The DSN.
+ */
+ private function _constructPdoDsn(array $params)
+ {
+ $dsn = '';
+ if (isset($params['host']) && $params['host'] != '') {
+ $dsn .= 'host=' . $params['host'] . ' ';
+ }
+ if (isset($params['port']) && $params['port'] != '') {
+ $dsn .= 'port=' . $params['port'] . ' ';
+ }
+ if (isset($params['dbname'])) {
+ $dsn .= 'dbname=' . $params['dbname'] . ' ';
+ }
+
+ return $dsn;
+ }
+
+ public function getDatabasePlatform()
+ {
+ return new \Doctrine\DBAL\Platforms\AkibanSrvPlatform();
+ }
+
+ public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
+ {
+ return new \Doctrine\DBAL\Schema\AkibanSrvSchemaManager($conn);
+ }
+
+ public function getName()
+ {
+ return 'akibansrv';
+ }
+
+ public function getDatabase(\Doctrine\DBAL\Connection $conn)
+ {
+ $params = $conn->getParams();
+ return $params['dbname'];
+ }
+}

0 comments on commit aba8430

Please sign in to comment.
Something went wrong with that request. Please try again.