\NyanORM
Basic Ubilling database abstraction prototype
Synopsis
class NyanORM
{
- // constants
- const LOG_PATH = 'exports/nyanorm.log';
- // members
- protected string $tableName = '';
- protected string $defaultPk = 'id';
- protected array $selectable = ;
- protected array $data = ;
- protected array $where = ;
- protected array $orWhere = ;
- protected array $order = ;
- protected array $join = ;
- protected integer $limit = 0;
- protected integer $offset = 0;
- protected bool $debug = false;
- protected bool $deepDebug = false;
- // methods
- public void __construct()
- protected void setTableName()
- public void selectable()
- public void join()
- public void joinOn()
- public void where()
- public void whereRaw()
- protected void destroyAllStructs()
- public void orWhere()
- public void orWhereRaw()
- protected void flushWhere()
- public void orderBy()
- protected void flushOrder()
- protected void flushSelectable()
- protected void flushJoin()
- protected void debugLog()
- protected string buildJoinString()
- protected string buildWhereString()
- protected string buildOrderString()
- public void limit()
- protected void flushLimit()
- protected string buildLimitString()
- protected string buildSelectableString()
- public array getAll()
- public void delete()
- public void data()
- public void dataArr()
- protected void flushData()
- public void save()
- public void create()
- public int getLastId()
- public int getFieldsCount()
- public int getFieldsSum()
- public void setDebug()
- public void setDefaultPk()
- protected string escapeField()
- public mixed|string checkRecExists()
- public string getTableName()
- public array getTableStructure()
Constants
Name | Value |
---|---|
LOG_PATH | 'exports/nyanorm.log' |
Members
protected
- $data
—
array
Contains key=>value data sets array for INSERT/UPDATE operations - $debug
—
bool
Object wide debug flag - $deepDebug
—
bool
Yet another debug flag, for full model dumping - $defaultPk
—
string
Contains default primary key field name for current instance model - $join
—
array
Contains JOIN expression. - $limit
—
int
Contains default query results limit - $offset
—
int
Contains default query limit offset - $orWhere
—
array
Cumulative where expressions array. This will used as OR glue. - $order
—
array
Contains ORDER by expressions for some queries - $selectable
—
array
Contains selectable fields list - $tableName
—
string
Contains table name for all instance operations - $where
—
array
Cumulative where expressions array. This will used as AND glue.
Methods
protected
- buildJoinString() — Build join expression from protected join expressions array.
- buildLimitString() — Builds SQL formatted limits string
- buildOrderString() — Retruns order expressions as string
- buildSelectableString() — Constucts field names which will be optionally used for data getting
- buildWhereString() — Builds where string expression from protected where expressions array
- debugLog() — Process some debugging data if required
- destroyAllStructs() — Flushes all available cumulative structures in safety reasons.
- escapeField() — Trying to correctly escape fields when using table_name.field_name.
- flushData() — Flushes current instance data set
- flushJoin() — Flushed join cumullative struct
- flushLimit() — Flushes limits values for further queries. No limits anymore! Meow!
- flushOrder() — Flushes order cumullative array
- flushSelectable() — Flushes selectable cumullative struct
- flushWhere() — Flushes both where cumullative arrays
- setTableName() — Table name automatic setter
public
- __construct() — Creates new model instance
- checkRecExists() — Returns true if record with such fields values already exists in current table
- create() — Creates new database record for current model instance.
- data() — Puts some data into protected data property for furrrrther save()/create() operations.
- dataArr() — Same as data() method, but works not with separate $field and $value data but with array of $fields => $values Useful if some "third-party" code returns an already prepared array of $fields => $values
- delete() — Deletes record from database. Where must be not empty!
- getAll() — Returns all records of current database object instance
- getFieldsCount() — Returns fields count in datatabase instance
- getFieldsSum() — Returns fields sum in datatabase instance
- getLastId() — Returns last ID key in table
- getTableName() — Simple getter for tableName property
- getTableStructure() — Returns model's base table structure
- join() — Setter for join (with USING) list which used in getAll.
- joinOn() — Setter for join (with ON) list which used in getAll.
- limit() — Sets query limits with optional offset
- orWhere() — Appends some OR where expression to protected prop for further database queries. Cleans it if all params empty.
- orWhereRaw() — Appends some raw OR where expression into cumullative where array. Or cleanup all if empty.
- orderBy() — Appends some order by expression to protected prop
- save() — Saves current model data fields changes to database.
- selectable() — Setter of filels list which will be optional used in getAll
- setDebug() — Enables or disables debug flag
- setDefaultPk() — Sets default primary key for model instance
- where() — Appends some where expression to protected prop for further database queries. Cleans it if all params empty.
- whereRaw() — Appends some raw where expression into cumullative where array. Or cleanup all if empty. Yeah.