Skip to content

Commit ede99e1

Browse files
committed
BC, start removing global functions where table name passed in, use the ones with preset table names
1 parent 68e18b8 commit ede99e1

File tree

7 files changed

+359
-187
lines changed

7 files changed

+359
-187
lines changed

lib/ezFunctions.php

Lines changed: 132 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,26 @@ function cleanInput($string)
530530
/**
531531
* Preforms a `select` method call on a already preset `table name`, and optional `prefix`
532532
*
533-
* This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
533+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
534534
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
535+
536+
* Returns an `result` set, given the
537+
* - column fields, conditions or conditional array.
538+
*
539+
* In the following format:
540+
* ```php
541+
* selecting(
542+
* columns,
543+
* innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition),
544+
* where( eq( columns, values, _AND ), like( columns, _d ) ),
545+
* groupBy( columns ),
546+
* having( between( columns, values1, values2 ) ),
547+
* orderBy( columns, desc ),
548+
* limit( numberOfRecords, offset ),
549+
* union(table, columnFields, conditions), // Returns an select SQL string with `UNION`
550+
* unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL`
551+
*);
552+
* ```
535553
*
536554
* @param mixed $columns fields, string or array
537555
* @param mixed ...$conditions - of the following parameters:
@@ -559,10 +577,11 @@ function selecting($columns = '*', ...$conditions)
559577
/**
560578
* Preforms a `insert` method call on a already preset `table name`, and optional `prefix`
561579
*
562-
* This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
580+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
563581
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
564582
*
565-
* @param array $keyValue - table fields, assoc array with key = value (doesn't need escaped)
583+
* Does an `insert` query with an array
584+
* @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping)
566585
* @return int|bool bool/id of inserted record, or false for error
567586
*/
568587
function inserting(array $keyValue)
@@ -574,7 +593,114 @@ function inserting(array $keyValue)
574593
}
575594

576595
/**
577-
* Set table `name` and `prefix` for global usage on calls to database **method/function** *names* ending with `ing`.
596+
* Preforms a `update` method call on a already preset `table name`, and optional `prefix`
597+
*
598+
* This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
599+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
600+
*
601+
* Does an `update` query with an array, by conditional operator array
602+
* @param array $keyValue, - table fields, assoc array with key = value (doesn't need escaped)
603+
* @param mixed ...$whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)`
604+
* - In the following format:
605+
*```js
606+
* eq('key/Field/Column', $value, _AND), // combine next expression
607+
* neq('key/Field/Column', $value, _OR), // will combine next expression if
608+
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
609+
* lt('key/Field/Column', $value)
610+
* lte('key/Field/Column', $value)
611+
* gt('key/Field/Column', $value)
612+
* gte('key/Field/Column', $value)
613+
* isNull('key/Field/Column')
614+
* isNotNull('key/Field/Column')
615+
* like('key/Field/Column', '_%')
616+
* notLike('key/Field/Column', '_%')
617+
* in('key/Field/Column', $values)
618+
* notIn('key/Field/Column', $values)
619+
* between('key/Field/Column', $value, $value2)
620+
* notBetween('key/Field/Column', $value, $value2)
621+
*```
622+
* @return mixed bool/results - false for error
623+
*/
624+
function updating(array $keyValue, ...$whereConditions)
625+
{
626+
$ezQuery = getInstance();
627+
return ($ezQuery instanceof DatabaseInterface)
628+
? $ezQuery->updating($keyValue, ...$whereConditions)
629+
: false;
630+
}
631+
632+
/**
633+
* Preforms a `create` method call on a already preset `table name`, and optional `prefix`
634+
*
635+
* This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
636+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
637+
*
638+
* Creates an database table with columns, by either:
639+
*```js
640+
* - array( column, datatype, ...value/options arguments ) // calls create_schema()
641+
* - column( column, datatype, ...value/options arguments ) // returns string
642+
* - primary( primary_key_label, ...primaryKeys) // returns string
643+
* - foreign( foreign_key_label, ...foreignKeys) // returns string
644+
* - unique( unique_key_label, ...uniqueKeys) // returns string
645+
*```
646+
* @param array ...$schemas An array of:
647+
*
648+
* - @param string `$column | CONSTRAINT,` - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY
649+
* - @param string `$type | $constraintName,` - data type for column/primary | foreign constraint name
650+
* - @param mixed `$size | ...$primaryForeignKeys,`
651+
* - @param mixed `$value,` - column should be NULL or NOT NULL. If omitted, assumes NULL
652+
* - @param mixed `$default` - Optional. It is the value to assign to the column
653+
*
654+
* @return mixed results of query() call
655+
*/
656+
function creating(...$schemas)
657+
{
658+
$ezQuery = getInstance();
659+
return ($ezQuery instanceof DatabaseInterface)
660+
? $ezQuery->creating(...$schemas)
661+
: false;
662+
}
663+
664+
/**
665+
* Preforms a `delete` method call on a already preset `table name`, and optional `prefix`
666+
*
667+
* This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
668+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
669+
*
670+
* Does an `delete` query with an array
671+
* @param $table, - database table to access
672+
* @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)`
673+
* - In the following format:
674+
*```js
675+
* eq('key/Field/Column', $value, _AND), // combine next expression
676+
* neq('key/Field/Column', $value, _OR), // will combine next expression if
677+
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
678+
* lt('key/Field/Column', $value)
679+
* lte('key/Field/Column', $value)
680+
* gt('key/Field/Column', $value)
681+
* gte('key/Field/Column', $value)
682+
* isNull('key/Field/Column')
683+
* isNotNull('key/Field/Column')
684+
* like('key/Field/Column', '_%')
685+
* notLike('key/Field/Column', '_%')
686+
* in('key/Field/Column', $values)
687+
* notIn('key/Field/Column', $values)
688+
* between('key/Field/Column', $value, $value2)
689+
* notBetween('key/Field/Column', $value, $value2)
690+
*```
691+
* @return mixed bool/results - false for error
692+
*/
693+
function deleting(...$whereConditions)
694+
{
695+
$ezQuery = getInstance();
696+
return ($ezQuery instanceof DatabaseInterface)
697+
? $ezQuery->deleting(...$whereConditions)
698+
: false;
699+
}
700+
701+
/**
702+
* Set table `name` and `prefix` for global usage on calls to database
703+
* **method/function** *names* ending with `ing`.
578704
*
579705
* @param string $name
580706
* @param string $prefix
@@ -603,7 +729,8 @@ function set_table(string $name = '')
603729
}
604730

605731
/**
606-
* Add a `prefix` to **append** to `table` name on calls to database **method/function** *names* ending with `ing`.
732+
* Add a `prefix` to **append** to `table` name on calls to database
733+
* **method/function** *names* ending with `ing`.
607734
*
608735
* @param string $append
609736
*/
@@ -616,49 +743,6 @@ function set_prefix(string $append = '')
616743
$ezQuery->setPrefix($append);
617744
}
618745

619-
/**
620-
* Returns an `SQL string` or `result` set, given the
621-
* - database table, column fields, conditions or conditional array.
622-
*
623-
* In the following format:
624-
* ```php
625-
* select(
626-
* table,
627-
* columns,
628-
* innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition),
629-
* where( eq( columns, values, _AND ), like( columns, _d ) ),
630-
* groupBy( columns ),
631-
* having( between( columns, values1, values2 ) ),
632-
* orderBy( columns, desc ),
633-
* limit( numberOfRecords, offset ),
634-
* union(table, columnFields, conditions), // Returns an select SQL string with `UNION`
635-
* unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL`
636-
*);
637-
* ```
638-
* @param $table, - database table to access
639-
* @param $columns, - table columns, string or array
640-
* @param mixed ...$conditions - of the following parameters:
641-
*
642-
* @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ)
643-
* - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()`
644-
* - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)`
645-
* @param $whereCondition, - `where` clause ( comparison(x, y, and) )
646-
* @param $groupBy, - `groupBy` over clause the results
647-
* @param $having, - `having` clause ( comparison(x, y, and) )
648-
* @param $orderby, - `orderby` clause for the query
649-
* @param $limit, - `limit` clause the number of records
650-
* @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove
651-
*
652-
* @return mixed|object result set - see docs for more details, or false for error
653-
*/
654-
function select($table = '', $columns = '*', ...$conditions)
655-
{
656-
$ezQuery = getInstance();
657-
return ($ezQuery instanceof DatabaseInterface)
658-
? $ezQuery->select($table, $columns, ...$conditions)
659-
: false;
660-
}
661-
662746
/**
663747
* Does an select into statement by calling selecting method
664748
* @param $newTable, - new database table to be created
@@ -1090,85 +1174,6 @@ function limit($numberOf, $offset = null)
10901174
: false;
10911175
}
10921176

1093-
/**
1094-
* Does an `insert` query with an array
1095-
* @param $table, - database table to access
1096-
* @param $keyValue - table fields, assoc array with key = value (doesn't need escaping)
1097-
* @return mixed bool/id of inserted record, or false for error
1098-
*/
1099-
function insert($table = '', $keyValue = null)
1100-
{
1101-
$ezQuery = getInstance();
1102-
return ($ezQuery instanceof DatabaseInterface)
1103-
? $ezQuery->insert($table, $keyValue)
1104-
: false;
1105-
}
1106-
1107-
/**
1108-
* Does an `update` query with an array, by conditional operator array
1109-
* @param $table, - database table to access
1110-
* @param $keyValue, - table fields, assoc array with key = value (doesn't need escaping)
1111-
* @param $whereConditions, - where clause `eq('x', $y, _AND), another clause - same as array(x, =, y, and, extra)`
1112-
* - In the following format:
1113-
*```js
1114-
* eq('key/Field/Column', $value, _AND), // combine next expression
1115-
* neq('key/Field/Column', $value, _OR), // will combine next expression if
1116-
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
1117-
* lt('key/Field/Column', $value)
1118-
* lte('key/Field/Column', $value)
1119-
* gt('key/Field/Column', $value)
1120-
* gte('key/Field/Column', $value)
1121-
* isNull('key/Field/Column')
1122-
* isNotNull('key/Field/Column')
1123-
* like('key/Field/Column', '_%')
1124-
* notLike('key/Field/Column', '_%')
1125-
* in('key/Field/Column', $values)
1126-
* notIn('key/Field/Column', $values)
1127-
* between('key/Field/Column', $value, $value2)
1128-
* notBetween('key/Field/Column', $value, $value2)
1129-
*```
1130-
* @return mixed bool/results - false for error
1131-
*/
1132-
function update($table = '', $keyValue = null, ...$whereConditions)
1133-
{
1134-
$ezQuery = getInstance();
1135-
return ($ezQuery instanceof DatabaseInterface)
1136-
? $ezQuery->update($table, $keyValue, ...$whereConditions)
1137-
: false;
1138-
}
1139-
1140-
/**
1141-
* Does an `delete` query with an array
1142-
* @param $table, - database table to access
1143-
* @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)`
1144-
* - In the following format:
1145-
*```js
1146-
* eq('key/Field/Column', $value, _AND), // combine next expression
1147-
* neq('key/Field/Column', $value, _OR), // will combine next expression if
1148-
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
1149-
* lt('key/Field/Column', $value)
1150-
* lte('key/Field/Column', $value)
1151-
* gt('key/Field/Column', $value)
1152-
* gte('key/Field/Column', $value)
1153-
* isNull('key/Field/Column')
1154-
* isNotNull('key/Field/Column')
1155-
* like('key/Field/Column', '_%')
1156-
* notLike('key/Field/Column', '_%')
1157-
* in('key/Field/Column', $values)
1158-
* notIn('key/Field/Column', $values)
1159-
* between('key/Field/Column', $value, $value2)
1160-
* notBetween('key/Field/Column', $value, $value2)
1161-
*```
1162-
* @return mixed bool/results - false for error
1163-
*/
1164-
function delete($table = null, ...$whereConditions)
1165-
{
1166-
$ezQuery = getInstance();
1167-
return ($ezQuery instanceof DatabaseInterface)
1168-
? $ezQuery->delete($table, ...$whereConditions)
1169-
: false;
1170-
}
1171-
11721177
/**
11731178
* Does an `replace` query with an array
11741179
* @param $table, - database table to access

0 commit comments

Comments
 (0)