-
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
Open
gronpipmaster
wants to merge
4
commits into
jpfuentes2:master
Choose a base branch
from
gronpipmaster:redshift-adapter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add RedshiftAdapter #496
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
caaa4e9
add RedshiftAdapter
gronpipmaster d006767
bug fixed check collumn pk
gronpipmaster 8605cf1
RedshiftAdapter extends PgsqlAdapter, replace all space to tabs, and …
gronpipmaster fb5c31d
revert !(->conn instanceof PgsqlAdapter || ->conn instanceof Redshift…
gronpipmaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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