Skip to content

Commit

Permalink
Add r\tableCreate r\tableList r\tableDrop shortcuts using default dat…
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mewes authored and danielmewes committed May 8, 2013
1 parent c931253 commit d8c5a9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/rdb/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ function table($tableName, $useOutdated = null)
return new Table(null, $tableName, $useOutdated);
}

function tableCreate($tableName, $options = null) {
return new TableCreate(null, $tableName, $options);
}
function tableDrop($tableName) {
return new TableDrop(null, $tableName);
}
function tableList() {
return new TableList(null);
}

function count()
{
$object = array('COUNT' => new BoolDatum(true));
Expand Down
26 changes: 18 additions & 8 deletions src/rdb/queries/tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

class TableList extends ValuedQuery
{
public function __construct(Db $database) {
public function __construct($database) {
if (isset($database) && !is_a($database, "\\r\\Db")) throw ("Database is not a Db object.");
$this->database = $database;
}

public function getPBTerm() {
$term = new pb\Term();
$term->set_type(pb\Term_TermType::PB_TABLE_LIST);
$term->set_args(0, $this->database->getPBTerm());
if (isset($this->database))
$term->set_args(0, $this->database->getPBTerm());
return $term;
}

Expand All @@ -18,7 +20,8 @@ public function getPBTerm() {

class TableCreate extends ValuedQuery
{
public function __construct(Db $database, $tableName, $options = null) {
public function __construct($database, $tableName, $options = null) {
if (isset($database) && !is_a($database, "\\r\\Db")) throw ("Database is not a Db object.");
if (!\is_string($tableName)) throw new RqlDriverError("Table name must be a string.");
if (isset($options)) {
if (!is_array($options)) throw new RqlDriverError("Options must be an array.");
Expand All @@ -38,9 +41,12 @@ public function __construct(Db $database, $tableName, $options = null) {
public function getPBTerm() {
$term = new pb\Term();
$term->set_type(pb\Term_TermType::PB_TABLE_CREATE);
$term->set_args(0, $this->database->getPBTerm());
$i = 0;
if (isset($this->database)) {
$term->set_args($i++, $this->database->getPBTerm());
}
$subDatum = new StringDatum($this->tableName);
$term->set_args(1, $subDatum->getPBTerm());
$term->set_args($i++, $subDatum->getPBTerm());
if (isset($this->options)) {
$i = 0;
foreach ($this->options as $key => $val) {
Expand All @@ -61,7 +67,8 @@ public function getPBTerm() {

class TableDrop extends ValuedQuery
{
public function __construct(Db $database, $tableName) {
public function __construct($database, $tableName) {
if (isset($database) && !is_a($database, "\\r\\Db")) throw ("Database is not a Db object.");
if (!\is_string($tableName)) throw new RqlDriverError("Table name must be a string.");
$this->database = $database;
$this->tableName = $tableName;
Expand All @@ -70,9 +77,12 @@ public function __construct(Db $database, $tableName) {
public function getPBTerm() {
$term = new pb\Term();
$term->set_type(pb\Term_TermType::PB_TABLE_DROP);
$term->set_args(0, $this->database->getPBTerm());
$i = 0;
if (isset($this->database)) {
$term->set_args($i++, $this->database->getPBTerm());
}
$subDatum = new StringDatum($this->tableName);
$term->set_args(1, $subDatum->getPBTerm());
$term->set_args($i++, $subDatum->getPBTerm());
return $term;
}

Expand Down

0 comments on commit d8c5a9a

Please sign in to comment.