-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RedshiftAdapter #496
base: master
Are you sure you want to change the base?
Add RedshiftAdapter #496
Changes from 3 commits
caaa4e9
d006767
8605cf1
fb5c31d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
/** | ||
* Adapter for Postgres (not completed yet) | ||
* | ||
* | ||
* @package ActiveRecord | ||
*/ | ||
class PgsqlAdapter extends Connection | ||
|
@@ -47,7 +47,7 @@ public function query_column_info($table) | |
WHERE c.oid = pg_index.indrelid | ||
AND a.attnum = ANY (pg_index.indkey) | ||
AND pg_index.indisprimary = 't' | ||
) IS NOT NULL AS pk, | ||
) IS NOT NULL AS pk, | ||
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE((SELECT pg_attrdef.adsrc | ||
FROM pg_attrdef | ||
WHERE c.oid = pg_attrdef.adrelid | ||
|
@@ -75,7 +75,7 @@ public function create_column(&$column) | |
$c->inflected_name = Inflector::instance()->variablize($column['field']); | ||
$c->name = $column['field']; | ||
$c->nullable = ($column['not_nullable'] ? false : true); | ||
$c->pk = ($column['pk'] ? true : false); | ||
$c->pk = ($column['pk'] == 't'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure about this change? I don't know postgres, so I can't be the judge of this.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://github.com/jpfuentes2/php-activerecord/blob/master/lib/adapters/PgsqlAdapter.php#L45-L50 here select value t, and default bool value in postrges is 't' or 'f' http://www.postgresql.org/docs/9.4/static/datatype-boolean.html#DATATYPE-BOOLEAN-EXAMPLE |
||
$c->auto_increment = false; | ||
|
||
if (substr($column['type'],0,9) == 'timestamp') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* @package ActiveRecord | ||
*/ | ||
namespace ActiveRecord; | ||
|
||
require_once __DIR__ . '/PgsqlAdapter.php'; | ||
|
||
/** | ||
* Adapter for Redshift postgres version < 8.0.2 (not completed yet) | ||
* | ||
* @package ActiveRecord | ||
*/ | ||
class RedshiftAdapter extends PgsqlAdapter | ||
{ | ||
public function supports_sequences() | ||
{ | ||
return false; | ||
} | ||
|
||
public function query_column_info($table) | ||
{ | ||
$sql = <<<SQL | ||
SELECT | ||
a.attname AS field, | ||
a.attlen, | ||
REPLACE(pg_catalog.format_type(a.atttypid, a.atttypmod), 'character varying', 'varchar') AS type, | ||
a.attnotnull AS not_nullable, | ||
(SELECT 't' | ||
FROM pg_index | ||
WHERE c.oid = pg_index.indrelid | ||
AND a.attnum = ANY ( | ||
string_to_array( | ||
textin( | ||
int2vectorout(pg_index.indkey) | ||
), '' | ||
) | ||
) | ||
AND pg_index.indisprimary = 't' | ||
) IS NOT NULL AS pk, | ||
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE((SELECT pg_attrdef.adsrc | ||
FROM pg_attrdef | ||
WHERE c.oid = pg_attrdef.adrelid | ||
AND pg_attrdef.adnum=a.attnum | ||
),'::[a-z_ ]+',''),'''$',''),'^''','') AS default | ||
FROM pg_attribute a, pg_class c, pg_type t | ||
WHERE c.relname = ? | ||
AND a.attnum > 0 | ||
AND a.attrelid = c.oid | ||
AND a.atttypid = t.oid | ||
ORDER BY a.attnum | ||
SQL; | ||
$values = array($table); | ||
return $this->query($sql,$values); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that
RedshiftAdapter
extendsPgsqlAdapter
,$this->conn instanceof PgsqlAdapter
would be sufficient here