Redbeanphp Class Reference Cheat Sheet by Richardjh
Total Page:16
File Type:pdf, Size:1020Kb
RedBeanPHP Class Reference Cheat Sheet by Richard Holloway (richardjh) via cheatography.com/478/cs/347/ About RedBeanPHP ORM Class Reference pt1 (cont) Class Reference pt1 (cont) Easy ORM for PHP and MySQL, PostgreSQL close() exportAll( $beans ) and many other database systems. Closes the database connect ion. Exports a collection of beans. Handy for Use the simplicity of NoSQL with the power of XML/JSON exports with a Javascript SQL. commit() framework like Dojo or ExtJS. http:// red bea nph p.com/ Facade Convience method for adapter transac tion system. Commits a transac tion. find( $type, $sql=null, $values=array() ) Class Reference pt1 Finds a bean using a type and a where configu reF aca deW ith Too lbox( $tb ) clause (SQL). As with most Query tools in addData base ( $key, $dsn, $user=n ull, Configures the facade, want to have a new RedBean you can provide values to be $pass=n ull, $frozen =false ) Writer? A new Object Database or a new inserted in the SQL statement by populating Adds a database to the facade, afterwards Adapter and you want it on-the- fly? Use this the value array parameter; you can either you can select the database using method to hot-swap your facade with a new use the question mark notation or the slot- selectD ata bas e($ key). toolbox. no tation (:keyna me). addTags ( $bean, $tagList ) convert ToB eans( $type, $rows ) findAll( $type, $sql=null, $values =ar ray() ) Part of RedBeanPHP Tagging API. Adds Converts a series of rows to beans. Finds a bean using a type and a where tags to a bean. If $tagList is a comma count( $beanType ) clause (SQL). As with most Query tools in separated list of tags all tags will be RedBean you can provide values to be Counts beans associated with the bean. You may also pass inserted in the SQL statement by populating an array instead of a string. debug( $tr=true ) the value array parameter; you can either use the question mark notation or the slot- areRela ted( $bean1, $bean2 ) Toggles DEBUG mode. In Debug mode all SQL that happens under the hood will be notation (:keyname). The findAll() method Checks whether a pair of beans is related printed to the screen. differs from the find() method in that it does N-M. This function does not check whether not assume a WHERE-c lause. the beans are related in N:1 way. depende ncies( $dep ) associate( $bean1, $bean2, $extra= null ) Sets a list of depende ncies. A dependency Class Reference pt2 list contains an entry for each dependent Associates two Beans. This method will bean. A dependent bean will be removed if findAnd Exp ort( $type, $sql=null, associate two beans with eachother. You the relation with one of the depende ncies $value= arr ay() ) can then get one of the beans by using the gets broken. related() function and providing the other Finds a bean using a type and a where clause (SQL). As with most Query tools in bean. dispense( $type, $num ) RedBean you can provide values to be batch( $type, $ids ) Dispenses a new RedBean OODB Bean for inserted in the SQL statement by populating use with the rest of the methods. Returns an array of beans. Pass a type and the value array parameter; you can either a series of ids and this method will bring you dispens eLa bels( $type, $labels ) use the question mark notation or the slot- the corresp ondig beans. no tation (:keyna me). The variation also A label is a bean with only an id, type and exports the beans (i.e. it returns arrays). begin() name property. This function will dispense beans for all entries in the array. The values findLast( $type, $sql=null, $values =ar ray() ) Facade Convience method for adapter of the array will be assigned to the name transac tion system. Begins a transac tion. Finds a bean using a type and a where property of each individual bean. clause (SQL). As with most Query tools in clearRe lat ions( $bean, $type ) dup( $bean, $trail, $pid=false ) RedBean you can provide values to be Clears all associated beans. Breaks all inserted in the SQL statement by populating Makes a copy of a bean. This method many-to -many associa tions of a bean and a the value array parameter; you can either makes a deep copy of the bean. specified type. use the question mark notation or the slot- exec( $sql, $values =ar ray() ) no tation (:keyna me). This variation returns Conveni ence function to execute Queries the last bean only. directly. Executes SQL. By Richard Holloway (richardjh) Published 16th April, 2012. Sponsored by CrosswordCheats.com cheatography.com/richardjh/ Last updated 5th June, 2014. Learn to solve cryptic crosswords! richardjh.org Page 1 of 3. http://crosswordcheats.com RedBeanPHP Class Reference Cheat Sheet by Richard Holloway (richardjh) via cheatography.com/478/cs/347/ Class Reference pt2 (cont) Class Reference pt2 (cont) Class Reference pt3 findOne( $type, $sql=null, $values =ar ray() ) getAssoc( $sql, $values =ar ray() ) isoDate( $time=null ) Finds a bean using a type and a where Conveni ence function to execute Queries Simple conveni ence function, returns ISO clause (SQL). As with most Query tools in directly. Executes SQL. Results will be date formatted represe nta tion of $time RedBean you can provide values to be returned as an associa tive array. The first isoDate Time( $time=null ) inserted in the SQL statement by populating column in the select clause will be used for the value array parameter; you can either the keys in this array and the second Simple conveni ence function, returns ISO use the question mark notation or the slot- column will be used for the values. If only date time formatted represe nta tion of $time. no tation (:keyna me). This variation returns one column is selected in the query, both load( $type, $id ) the first bean only. key and value of the array will have the Loads the bean with the given type and id value of this field for each row. findOrD isp ense( $type, $sql, $values ) and returns it. getCell( $sql, $values =ar ray() ) Conveni ence method. Tries to find beans of log( $filename ) a certain type, if no beans are found, it Conveni ence function to execute Queries Activates TimeLine Schema Alteration dispenses a bean of that type. directly. Executes SQL. monitoring and Query logging. freeze( $tr=true ) getCol( $sql, $values =ar ray() ) nuke() Toggles fluid or frozen mode. In fluid mode Conveni ence function to execute Queries Nukes the entire database the database structure is adjusted to directly. Executes SQL. accomodate your objects. In frozen mode query( $method, $sql, $values ) getColu mns( $table ) this is not the case. Internal Query function, executes the Returns a list of columns. Format of this desired query. Used by all facade query gatherLabels( $beans ) array: array( fieldname => type ) Note that functions. This keeps things DRY. Gathers labels from beans. This function this method only works in fluid mode loops through the beans, collects the values because it might be quite heavy on related( $bean, $type, $sql=null, of the name properties of each individual production servers! $values =ar ray() ) bean and stores the names in a new array. getRow( $sql, $values =ar ray() ) Returns all the beans associated with The array then gets sorted using the default $bean. This method will return an array Conveni ence function to execute Queries sort function of PHP (sort). containing all the beans that have been directly. Executes SQL. genSlots( $array ) associated once with the associa te() getVers ion() function and are still associated with the Generates question mark slots for an array bean specified. of values. Get version related One( $bean, $type, $sql=null, getAll( $sql, $values =ar ray() ) graph( $array, $filter Emp ty= false ) $values =ar ray() ) Conveni ence function to execute Queries facade method for Cooker Graph. Returns only single associated bean. directly. Executes SQL. hasTags( $bean, $tags, $all=false ) rollback() Part of RedBeanPHP Tagging API. Tests whether a bean has been associated with Facade Convience method for adapter one ore more of the listed tags. If the third transac tion system. Rolls back a parameter is TRUE this method will return transac tion. TRUE only if all tags that have been selectD ata base( $key ) specified are indeed associated with the Selects a different database for the Facade given bean, otherwise FALSE. If the third to work with. parameter is FALSE this method will return TRUE if one of the tags matches, FALSE if none match. By Richard Holloway (richardjh) Published 16th April, 2012. Sponsored by CrosswordCheats.com cheatography.com/richardjh/ Last updated 5th June, 2014. Learn to solve cryptic crosswords! richardjh.org Page 2 of 3. http://crosswordcheats.com RedBeanPHP Class Reference Cheat Sheet by Richard Holloway (richardjh) via cheatography.com/478/cs/347/ Class Reference pt3 (cont) Class Reference pt3 (cont) setup( $dsn=null, $userna me= null, trashAll( $beans ) $password=null ) Short hand function to trash a set of beans Kickstarts redbean for you. This method at once. For informa tion please consult the should be called before you start using R::trash() function. A loop saver. RedBean. The Setup() method can be called unassoc iate( $bean1, $bean2, fast=false ) without any arguments, in this case it will try to create a SQLite database in /tmp called Breaks the associa tion between two beans. red.db (this only works on UNIX-like This functions breaks the associa tion systems). between a pair of beans. After calling this functions the beans will no longer be store( $bean ) associated with eachother.