$type where $field is the name of the column and $type
* is a database specific description of the datatype.
*
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type type of bean you want to obtain a column list of
*
* @return array
*/
public function getColumns( $type );
/**
* Returns the Column Type Code (integer) that corresponds
* to the given value type. This method is used to determine the minimum
* column type required to represent the given value.
*
* @param string $value value
*
* @return integer
*/
public function scanType( $value, $alsoScanSpecialForTypes = FALSE );
/**
* This method will add a column to a table.
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type name of the table
* @param string $column name of the column
* @param integer $field data type for field
*
* @return void
*/
public function addColumn( $type, $column, $field );
/**
* Returns the Type Code for a Column Description.
* Given an SQL column description this method will return the corresponding
* code for the writer. If the include specials flag is set it will also
* return codes for special columns. Otherwise special columns will be identified
* as specified columns.
*
* @param string $typedescription description
* @param boolean $includeSpecials whether you want to get codes for special columns as well
*
* @return integer
*/
public function code( $typedescription, $includeSpecials = FALSE );
/**
* This method will widen the column to the specified data type.
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type type / table that needs to be adjusted
* @param string $column column that needs to be altered
* @param integer $datatype target data type
*
* @return void
*/
public function widenColumn( $type, $column, $datatype );
/**
* Selects records from the database.
* This methods selects the records from the database that match the specified
* type, conditions (optional) and additional SQL snippet (optional).
*
* @param string $type name of the table you want to query
* @param array $conditions criteria ( $column => array( $values ) )
* @param string $addSQL additional SQL snippet
* @param array $bindings bindings for SQL snippet
*
* @return array
*/
public function queryRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() );
/**
* Selects records from the database and returns a cursor.
* This methods selects the records from the database that match the specified
* type, conditions (optional) and additional SQL snippet (optional).
*
* @param string $type name of the table you want to query
* @param array $conditions criteria ( $column => array( $values ) )
* @param string $addSQL additional SQL snippet
* @param array $bindings bindings for SQL snippet
*
* @return Cursor
*/
public function queryRecordWithCursor( $type, $addSql = NULL, $bindings = array() );
/**
* Returns records through an intermediate type. This method is used to obtain records using a link table and
* allows the SQL snippets to reference columns in the link table for additional filtering or ordering.
*
* @param string $sourceType source type, the reference type you want to use to fetch related items on the other side
* @param string $destType destination type, the target type you want to get beans of
* @param mixed $linkID ID to use for the link table
* @param string $addSql Additional SQL snippet
* @param array $bindings Bindings for SQL snippet
*
* @return array
*/
public function queryRecordRelated( $sourceType, $destType, $linkID, $addSql = '', $bindings = array() );
/**
* Returns the row that links $sourceType $sourcID to $destType $destID in an N-M relation.
*
* @param string $sourceType source type, the first part of the link you're looking for
* @param string $destType destination type, the second part of the link you're looking for
* @param string $sourceID ID for the source
* @param string $destID ID for the destination
*
* @return array|null
*/
public function queryRecordLink( $sourceType, $destType, $sourceID, $destID );
/**
* Counts the number of records in the database that match the
* conditions and additional SQL.
*
* @param string $type name of the table you want to query
* @param array $conditions criteria ( $column => array( $values ) )
* @param string $addSQL additional SQL snippet
* @param array $bindings bindings for SQL snippet
*
* @return integer
*/
public function queryRecordCount( $type, $conditions = array(), $addSql = NULL, $bindings = array() );
/**
* Returns the number of records linked through $linkType and satisfying the SQL in $addSQL/$bindings.
*
* @param string $sourceType source type
* @param string $targetType the thing you want to count
* @param mixed $linkID the of the source type
* @param string $addSQL additional SQL snippet
* @param array $bindings bindings for SQL snippet
*
* @return integer
*/
public function queryRecordCountRelated( $sourceType, $targetType, $linkID, $addSQL = '', $bindings = array() );
/**
* Returns all rows of specified type that have been tagged with one of the
* strings in the specified tag list array.
*
* Note that the additional SQL snippet can only be used for pagination,
* the SQL snippet will be appended to the end of the query.
*
* @param string $type the bean type you want to query
* @param array $tagList an array of strings, each string containing a tag title
* @param boolean $all if TRUE only return records that have been associated with ALL the tags in the list
* @param string $addSql addition SQL snippet, for pagination
* @param array $bindings parameter bindings for additional SQL snippet
*
* @return array
*/
public function queryTagged( $type, $tagList, $all = FALSE, $addSql = '', $bindings = array() );
/**
* This method should update (or insert a record), it takes
* a table name, a list of update values ( $field => $value ) and an
* primary key ID (optional). If no primary key ID is provided, an
* INSERT will take place.
* Returns the new ID.
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type name of the table to update
* @param array $updatevalues list of update values
* @param integer $id optional primary key ID value
*
* @return integer
*/
public function updateRecord( $type, $updatevalues, $id = NULL );
/**
* Deletes records from the database.
* @note $addSql is always prefixed with ' WHERE ' or ' AND .'
*
* @param string $type name of the table you want to query
* @param array $conditions criteria ( $column => array( $values ) )
* @param string $sql additional SQL
* @param array $bindings bindings
*
* @return void
*/
public function deleteRecord( $type, $conditions = array(), $addSql = '', $bindings = array() );
/**
* Deletes all links between $sourceType and $destType in an N-M relation.
*
* @param string $sourceType source type
* @param string $destType destination type
* @param string $sourceID source ID
*
* @return void
*/
public function deleteRelations( $sourceType, $destType, $sourceID );
/**
* @see QueryWriter::addUniqueConstaint
*/
public function addUniqueIndex( $type, $columns );
/**
* This method will add a UNIQUE constraint index to a table on columns $columns.
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type target bean type
* @param array $columnsPartOfIndex columns to include in index
*
* @return void
*/
public function addUniqueConstraint( $type, $columns );
/**
* This method will check whether the SQL state is in the list of specified states
* and returns TRUE if it does appear in this list or FALSE if it
* does not. The purpose of this method is to translate the database specific state to
* a one of the constants defined in this class and then check whether it is in the list
* of standard states provided.
*
* @param string $state SQL state to consider
* @param array $list list of standardized SQL state constants to check against
*
* @return boolean
*/
public function sqlStateIn( $state, $list );
/**
* This method will remove all beans of a certain type.
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type bean type
*
* @return void
*/
public function wipe( $type );
/**
* This method will add a foreign key from type and field to
* target type and target field.
* The foreign key is created without an action. On delete/update
* no action will be triggered. The FK is only used to allow database
* tools to generate pretty diagrams and to make it easy to add actions
* later on.
* This methods accepts a type and infers the corresponding table name.
*
*
* @param string $type type that will have a foreign key field
* @param string $targetType points to this type
* @param string $property field that contains the foreign key value
* @param string $targetProperty field where the fk points to
* @param string $isDep whether target is dependent and should cascade on update/delete
*
* @return void
*/
public function addFK( $type, $targetType, $property, $targetProperty, $isDep = false );
/**
* This method will add an index to a type and field with name
* $name.
* This methods accepts a type and infers the corresponding table name.
*
* @param string $type type to add index to
* @param string $name name of the new index
* @param string $property field to index
*
* @return void
*/
public function addIndex( $type, $name, $property );
/**
* Checks and filters a database structure element like a table of column
* for safe use in a query. A database structure has to conform to the
* RedBeanPHP DB security policy which basically means only alphanumeric
* symbols are allowed. This security policy is more strict than conventional
* SQL policies and does therefore not require database specific escaping rules.
*
* @param string $databaseStructure name of the column/table to check
* @param boolean $noQuotes TRUE to NOT put backticks or quotes around the string
*
* @return string
*/
public function esc( $databaseStructure, $dontQuote = FALSE );
/**
* Removes all tables and views from the database.
*
* @return void
*/
public function wipeAll();
/**
* Renames an association. For instance if you would like to refer to
* album_song as: track you can specify this by calling this method like:
*
*
* renameAssociation('album_song','track')
*
*
* This allows:
*
*
* $album->sharedSong
*
*
* to add/retrieve beans from track instead of album_song.
* Also works for exportAll().
*
* This method also accepts a single associative array as
* its first argument.
*
* @param string|array $fromType original type name, or array
* @param string $toType new type name (only if 1st argument is string)
*
* @return void
*/
public function renameAssocTable( $fromType, $toType = NULL );
/**
* Returns the format for link tables.
* Given an array containing two type names this method returns the
* name of the link table to be used to store and retrieve
* association records. For instance, given two types: person and
* project, the corresponding link table might be: 'person_project'.
*
* @param array $types two types array($type1, $type2)
*
* @return string
*/
public function getAssocTable( $types );
/**
* Given a bean type and a property, this method
* tries to infer the fetch type using the foreign key
* definitions in the database.
* For instance: project, student -> person.
* If no fetchType can be inferred, this method will return NULL.
*
* @note QueryWriters do not have to implement this method,
* it's optional. A default version is available in AQueryWriter.
*
* @param $type the source type to fetch a target type for
* @param $property the property to fetch the type of
*
* @return string|NULL
*/
public function inferFetchType( $type, $property );
}