/** * Drop a database table * Destructive and dangerous - drops entire table and all data * Will throw errors if user does not have proper permissions */ public function dropDatabase($database) { $sql = "DROP DATABASE " . $database; // Add query to log Spot_Log::addQuery($this, $sql); return $this->connection()->exec($sql); }
/** * Build a Mongo query * * Finding: @link http://us.php.net/manual/en/mongocollection.find.php * Fields: @link http://us.php.net/manual/en/mongocursor.fields.php * Cursor: @link http://us.php.net/manual/en/class.mongocursor.php * Sorting: @link http://us.php.net/manual/en/mongocursor.sort.php */ public function read(Spot_Query $query, array $options = array()) { // Get MongoCursor first - it's required for other options $criteria = $this->queryConditions($query); $cursor = $this->mongoCollection($query->datasource)->find($criteria); // Organize 'order' options for sorting $order = array(); if ($query->order) { foreach ($query->order as $oField => $oSort) { // MongoDB sorting: ASC: 1, DESC: 2 $order[$oField] = $oSort == 'DESC' ? 2 : 1; } } $cursor->sort($order); // @todo GROUP BY - Not supported YET (!) // @link http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Group if ($query->group) { throw new Spot_Exception("Grouping for the Mongo adapter has not currently been implemented. Would you like to contribute? :)"); } // LIMIT & OFFSET (Skip) if ($query->limit) { $cursor->limit($query->limit); } if ($query->offset) { $cursor->skip($query->offset); } // Add query to log Spot_Log::addQuery($this, $criteria); // Return collection return $this->toCollection($query, $cursor); }
public function count(\Spot\Query $query, array $options = array()) { // Load criteria $criteria = $this->queryConditions($query); //find and return count $count = $this->mongoCollection($query->datasource)->find($criteria)->count(); // Add query to log Spot_Log::addQuery($this, $criteria); // Return count return is_numeric($count) ? (int) $count : 0; }