You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### PHPFUI\ORM a minimal Object Relational Mapper (ORM) for MySQL, MariaDB and SQLite3
4
-
Why another PHP ORM? In writing minimal and fast websites, it was determined that existing PHP ORM solutions were overly complex. **PHPFUI\ORM** is less than 6k lines of code in under 50 files. It is designed to have a minimal memory footprint and excellent execution times for most database needs.
4
+
Why another PHP ORM? In writing minimal and fast websites, it was determined that existing PHP ORM solutions were overly complex. **PHPFUI\ORM** is a little more than 6K lines of code in under 50 files. It is designed to have a minimal memory footprint and excellent execution times for most database needs.
5
5
6
6
**PHPFUI\ORM** is not an attempt to write an abstraction around SQL as other ORMs do, rather it is a way to work with SQL that closely matches the semantics of SQL, with the power of PHP objects. It allows PHP to manipulate SQL queries without having to write SQL in plain text. This is very useful for queries generated via user interfaces where the user is given a lot of flexability in how a query is defined.
Copy file name to clipboardExpand all lines: docs/1. Setup.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ Deletion of unused models should be done manually when the table is removed from
23
23
## PHP Class Naming Conventions
24
24
All **PHPFUI\ORM** classes and namespaces use StudlyCase naming conventions. SQL table names are used the generate the PHP class names. Case is preserved except the first letter is the converted to upper case. Table names with underscores are converted to StudlyCase and underscores are removed. Field names are not affected and left unchanged.
25
25
26
-
Each table will generate 3 classes (4 if validators are generated) with the same class name, but in the specified namespaces (see below). **Definition** and **Validation** namespaces are children of the record namespace.
26
+
Each table will generate 3 classes (4 if validators are generated) with the same class name, but in the specified namespaces (see below). **Definition** and **Validation** namespaces are children of the **Record** namespace.
27
27
28
28
## Configuration
29
29
**PHPFUI\ORM** needs the following information to work with your code:
Copy file name to clipboardExpand all lines: docs/2. Active Record.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ A **Record** constructor attempts to read the specified row from the table. It c
31
31
-**array** record is attempted to be read from database using the values of the fields provided.
32
32
-**null** (default) constructs an empty object.
33
33
34
-
Both int and string parameters to the constructor are type checked. Calling the constructor with a parameter can be see as the same as, but with type checking:
34
+
Both int and string parameters to the constructor are type checked. Calling the constructor with a parameter can be see as the same as the following, but with type checking:
35
35
```php
36
36
$customer = new \App\Record\Customer();
37
37
$customer->read($value);
@@ -41,7 +41,7 @@ $customer->read($value);
41
41
-**insert**() or **create**()
42
42
* Adds the current record to the database. If the primary key already exists in the database, the insert fails. The auto increment primary key is updated with the value inserted.
43
43
* insert() returns the primary key value inserted, true if no primary key and the record was successfully inserted or false on error.
44
-
-**insertOrUpdate**()
44
+
-**insertOrUpdate**() or **save**()
45
45
* Will try to insert the record and on a duplicate key, will update the record with the current values.
46
46
* insertOrUpdate() returns the same values as insert().
47
47
* If the record only consists of primary keys, then this method is equivalent to insertOrIgnore().
@@ -80,7 +80,7 @@ $customer->read($value);
80
80
* Returns an array of errors indexed by field name. Empty array means the record has correctly validated.
81
81
82
82
## Related Records
83
-
Related records are indicated by field name ending in the id suffix (default: 'Id'). The field name before the 'Id' must be the same as the corresponding table name. See See [Virtual Fields](<https://github.com/phpfui/ORM/blob/main/docs/5. Virtual Fields.md>) for more advanced Related Records.
83
+
Related records are indicated by field name ending in the id suffix (default: 'Id'). The field name before the 'Id' must be the same as the corresponding table name. See See [Virtual Fields](https://github.com/phpfui/ORM/blob/main/docs/5.%20Virtual%20Fields.md) for more advanced Related Records.
84
84
85
85
### Accessing Related Records
86
86
You access the related record by the base field name (without the id suffix). The field with the id suffix is the primary key of the related record.
@@ -145,7 +145,7 @@ Notice that we did not have to save the customer record. By assigning it to the
145
145
You can always just assign the id's directly: `$orderDetail->purchase_order_id = $purchase_order->purchase_order_id;`. Saving the OrderDetail record is up to you.
146
146
147
147
### Other Types Of Related Records
148
-
See [Virtual Fields](<https://github.com/phpfui/ORM/blob/main/docs/5. Virtual Fields.md>) for information on how to impliment child or many to many relationships.
148
+
See [Virtual Fields](https://github.com/phpfui/ORM/blob/main/docs/5.%20Virtual%20Fields.md) for information on how to impliment child or many to many relationships.
149
149
150
150
### Multi Database Support
151
151
Related Records will always return a record from the currently selected database. Care must be taken when using multiple databases that any references to related records are done while the correct database instance is active. Cursors will continue to use the database in effect when they were created.
Copy file name to clipboardExpand all lines: docs/3. Active Table.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# PHPFUI\ORM Active Table
2
-
While an **Active Record** represents a single row in the database table, an **Active Table** represents the entire table. [\PHPFUI\ORM\Table](http://phpfui.com/?n=PHPFUI%5CORM&c=Table) allows you to find, select, update and delete multiple records at a time.
2
+
While an **Active Record** represents a single row in the database table, an **Active Table** represents the entire table. [\PHPFUI\ORM\Table](http://phpfui.com/?n=PHPFUI%5CORM&c=Table) allows you to find, select, update, insert and delete multiple records at a time.
3
3
4
4
**Active Tables** are easy to manipulate in code and free you from constructing SQL statements with plain text.
5
5
@@ -72,7 +72,7 @@ $condition->or($conditionB);
72
72
```
73
73
The above will produce the PDO equivalent of `(lastName >= 'R' AND lastName < 'S') OR (lastName >= 'F' AND lastName < 'G')`
74
74
75
-
The [In](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=In) and [NotIn](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotIn) operators require the second parameter to [Condition](http://phpfui.com/?n=PHPFUI\ORM&c=Condition). The [Like](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=Like) and [NotLike](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotLike) operators will respect the % and _ characters, but you are responsible for putting them in the correct positions.
75
+
The [In](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=In) and [NotIn](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotIn) operators require the second parameter to [Condition](http://phpfui.com/?n=PHPFUI\ORM&c=Condition) to be an array. The [Like](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=Like) and [NotLike](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotLike) operators will respect the % and _ characters, but you are responsible for putting them in the correct positions.
76
76
77
77
#### Literal and Field classes
78
78
Sometimes you need to compare something to a SQL constant or call a function. You can use `new \PHPFUI\ORM\Literal('CURRENT_TIMESTAMP()')`.
Copy file name to clipboardExpand all lines: docs/4. Cursors.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ foreach ($customerTable->getDataObjectCursor() as $record)
35
35
}
36
36
```
37
37
### RecordCursor
38
-
A **RecordCursor** returns a **\PHPFUI\ORM\Record** typed from the table. It is a fully functional **Active Record**. It also implements [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php), but is not an array.
38
+
A **RecordCursor** returns a [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) typed from the table. It is a fully functional **Active Record**. It also implements [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php), but is not an array.
@@ -49,5 +49,5 @@ foreach ($customerTable->getDataObjectCursor() as $record)
49
49
}
50
50
```
51
51
52
-
Please note that the **RecordCursor** reuses the same **\PHPFUI\ORM\Record** instance to conserve memory, so they will need to be cloned if added to an array or cursor. **DataObjectCursor** and **ArrayCursor** return new objects.
52
+
Please note that the [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) reuses the same **\PHPFUI\ORM\Record** instance to conserve memory, so they will need to be cloned if added to an array or cursor. **DataObjectCursor** and **ArrayCursor** return new objects.
Copy file name to clipboardExpand all lines: docs/5. Virtual Fields.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ You can define virtual fields with get and set semantics for any **\App\Record**
5
5
6
6
Every **\App\Record** class has a static $virtualFields array defined. The key of the array is the name of the virtual key. The value for each virtual field is an array of strings. The first string is the virtual field class name. Subsequent parameters are are passed the the **getValue** and **setValue** methods.
7
7
8
-
Note that virtual fields are created each time they are accessed and not stored or cached in the \PHPFUI\ORM\Record object. This means you can not change the virtual field on the Record object itself. You can only assign it to the Record object, which will store the value represented by the virtual field in the object, but not the virtual field itself.
8
+
Note that virtual fields are created each time they are accessed and not stored or cached in the [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) object. This means you can not change the virtual field on the **Record** object itself. You can only assign it to the Record object, which will store the value represented by the virtual field in the object, but not the virtual field itself.
9
9
10
10
The **VirtualField** class has two properties that will always be defined for use by the derived class:
11
11
* $currentRecord is the current record that the virtual field should be based on.
@@ -35,13 +35,13 @@ Sometimes you can't name a related record with the name of the table. For examp
35
35
You can make them all return employees with the following virtual field definitions:
36
36
```php
37
37
class Order extends \Tests\App\Record\Definition\Order
@@ -88,7 +88,7 @@ class Order extends \Tests\App\Record\Definition\Order
88
88
}
89
89
```
90
90
91
-
By default, child records will be automatically deleted when the parent record is deleted. You can disable this functionality for a specific record class by setting the static property $deleteChildren to false, or using your own Children class.
91
+
By default, child records will be automatically deleted when the parent record is deleted. You can disable this functionality for a specific [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) class by setting the static property $deleteChildren to false, or using your own Children class.
92
92
93
93
### Usage
94
94
```php
@@ -137,12 +137,12 @@ Use \PHPFUI\ORM\Cast virtual field to accommplish this. The Cast virtual field w
137
137
### Usage
138
138
```php
139
139
class Invoice extends \Tests\App\Record\Definition\Order
Copy file name to clipboardExpand all lines: docs/7. Validation.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# PHPFUI\ORM Validation
2
2
*__Note__: Referenced namespaces in this document refer to the **PHPFUI\ORM** defaults.*
3
3
4
-
Validator is an abstract class for Record validation See [\PHPFUI\ORM\Validator](http://phpfui.com/?n=PHPFUI%5CORM&c=Validator) namespace for examples.
4
+
Validator is an abstract class for **\App\Record** validation See [\PHPFUI\ORM\Validator](http://phpfui.com/?n=PHPFUI%5CORM&c=Validator) namespace for examples.
5
5
6
6
Individual validators are listed in the table below. Validators can be combined. For example, a field can be **required**, and have a **minlength** and **maxlength**. Validators can have parameters. Parameters are separated by a colon (:) and then commas for each separate parameter.
7
7
@@ -22,9 +22,9 @@ foreach ($validationErrors as $field => $fieldErrors)
22
22
{
23
23
echo "Field {$field} has the following errors:\n";
24
24
foreach ($fieldErrors as $error)
25
-
{
26
-
echo $error . "\n";
27
-
}
25
+
{
26
+
echo $error . "\n";
27
+
}
28
28
}
29
29
```
30
30
@@ -73,7 +73,7 @@ foreach ($validationErrors as $field => $fieldErrors)
73
73
| year_month | Loosely formatted Year Month | None |
74
74
75
75
## Field Comparison Validators
76
-
You can compare one field to another on the same Record with the field validators.
76
+
You can compare one field to another on the same **\App\Record** with the field validators.
77
77
* gt_field
78
78
* lt_field
79
79
* gte_field
@@ -113,10 +113,10 @@ You can also pass an optional method to validate to perform more complex validat
Copy file name to clipboardExpand all lines: docs/9. Transactions.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ $transaction = new \PHPFUI\ORM\Transaction();
7
7
if ($allGood)
8
8
{
9
9
$transaction->commit();
10
-
}
10
+
}
11
11
else
12
12
{
13
13
$transaction->rollBack();
14
-
}
14
+
}
15
15
```
16
16
The above creates a transaction on the current database. Commit and rollback will also be called on the correct database even if you are working on another database at the time.
0 commit comments