Skip to content

Commit 86ed1f5

Browse files
committed
More postgre porting
1 parent 0a38b16 commit 86ed1f5

32 files changed

+453
-249
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# PHPFUI\ORM [![Tests](https://github.com/phpfui/ORM/actions/workflows/tests.yml/badge.svg)](https://github.com/phpfui/ORM/actions?query=workflow%3Atests) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/ORM.svg)](https://packagist.org/packages/phpfui/ORM) ![](https://img.shields.io/badge/PHPStan-level%206-brightgreen.svg?style=flat)
22

33
### PHPFUI\ORM a minimal Object Relational Mapper (ORM) for MySQL, MariaDB, PostGre 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 a little more than 6.7K lines of code in 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 7K lines of code in 52 files. It is designed to have a minimal memory footprint and excellent execution times for most database needs.
55

66
**PHPFUI\ORM** demonstrates superior performance for both speed and memory usage verses other ORMs. This is proven by a [comparison of PHPFUI\ORM to Other ORMs](https://github.com/phpfui/php-orm-sql-benchmarks) for different SQL implementations.
77

88
**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.
99

10-
### Version 2.0 requires updated Definition classes
11-
You will need to run the \PHPFUI\ORM\Tool\Generate\CRUD class against your database. See scripts/generateCRUD.php for an example.
12-
1310
## Features
1411
- **Active Records** A fully type checked object interface and implement basic CRUD functionality.
1512
- **Active Tables** Full table operations (select, update, insert and delete) including support for where, having, limits, ordering, grouping, joins and unions.

Tests/Fixtures/MigrationWrapper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public function alterColumnTest(string $table, string $field, string $parameters
4343
return $this->alterColumn($table, $field, $parameters);
4444
}
4545

46-
public function renameColumnTest(string $table, string $field, string $newName) : bool
47-
{
48-
return $this->renameColumn($table, $field, $newName);
49-
}
50-
5146
/**
5247
* @param array<string> $keys
5348
*/
@@ -110,6 +105,11 @@ public function indexExistsTest(string $table, string $indexName) : bool
110105
return $this->indexExists($table, $indexName);
111106
}
112107

108+
public function renameColumnTest(string $table, string $field, string $newName) : bool
109+
{
110+
return $this->renameColumn($table, $field, $newName);
111+
}
112+
113113
public function renameTableTest(string $oldName, string $newName) : bool
114114
{
115115
return $this->renameTable($oldName, $newName);

Tests/Unit/DeleteTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function testRecordDelete() : void
3333
$this->assertEquals(55, $table->count());
3434
$this->assertEquals('', \PHPFUI\ORM::getLastError());
3535
$purchaseorderdetail = new \Tests\App\Record\PurchaseOrderDetail(245);
36-
$this->assertEquals('2006-01-22 00:00:00', $purchaseorderdetail->date_received);
36+
$time = \PHPFUI\ORM::getInstance()->postGre ? '2006-01-22 00:00:00+00' : '2006-01-22 00:00:00';
37+
$this->assertEquals($time, $purchaseorderdetail->date_received);
3738
$purchaseorderdetail->delete();
3839
$this->assertEquals('', \PHPFUI\ORM::getLastError());
3940
$this->assertEquals(54, $table->count());

Tests/Unit/InsertTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public function testDateNullInsert() : void
1111
$test->dateRequired = $date = \gmdate('Y-m-d');
1212
$timeStamp = \gmdate('Y-m-d H:i:s');
1313
$id = $test->insert();
14+
$this->assertNotEquals(0, $id, 'id is zero');
15+
1416
$insertedTest = new \Tests\App\Record\DateRecord($id);
1517

1618
$this->assertNull($insertedTest->dateDefaultNull, 'dateDefaultNull is not null');
@@ -27,13 +29,11 @@ public function testDateRequiredInsert() : void
2729
{
2830
$test = new \Tests\App\Record\DateRecord();
2931
$id = $test->insert();
30-
$this->assertNotEmpty(\PHPFUI\ORM::getLastError());
3132
$this->assertEquals(0, $id, '$id is not zero');
3233
$insertedTest = new \Tests\App\Record\DateRecord($id);
3334
$this->assertNull($insertedTest->dateDefaultNull, 'dateDefaultNull is not after insert');
3435
$this->assertEquals('2000-01-02', $insertedTest->dateDefaultNullable, 'dateDefaultNullable has bad default value');
3536
$this->assertEquals('2000-01-02', $insertedTest->dateDefaultNotNull, 'dateDefaultNotNull has bad default value');
36-
3737
}
3838

3939
public function testInsertOrIgnore() : void
@@ -59,19 +59,23 @@ public function testInsertOrIgnore() : void
5959
$customer->web_page = 'http://www.phpfui.com';
6060
$customer->zip_postal_code = '12345';
6161
$id = $customer->insertOrIgnore();
62+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
6263
$this->assertGreaterThan(0, $id);
6364
$this->assertEquals(30, $customerTable->count());
65+
$this->assertTrue($transaction->commit());
6466

6567
$newCustomer = new \Tests\App\Record\Customer($id);
6668
$this->assertEquals('12345', $newCustomer->zip_postal_code);
6769
$newCustomer->zip_postal_code = '54321';
6870
$result = $newCustomer->insertOrIgnore();
6971
$this->assertEquals(0, $result);
70-
$this->assertEmpty(\PHPFUI\ORM::getLastError());
72+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7173

7274
$updatedCustomer = new \Tests\App\Record\Customer($id);
75+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7376
$this->assertEquals('12345', $updatedCustomer->zip_postal_code);
74-
$this->assertTrue($transaction->rollBack());
77+
$updatedCustomer->delete();
78+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7579
$this->assertEquals(29, $customerTable->count());
7680
}
7781

@@ -98,13 +102,17 @@ public function testInsertOrUpdate() : void
98102
$customer->web_page = 'http://www.phpfui.com';
99103
$customer->zip_postal_code = '12345';
100104
$id = $customer->insertOrUpdate();
105+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
101106
$this->assertGreaterThan(0, $id);
102107
$this->assertEquals(30, $customerTable->count());
108+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
103109

104110
$newCustomer = new \Tests\App\Record\Customer($id);
111+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
105112
$this->assertEquals('12345', $newCustomer->zip_postal_code);
106113
$newCustomer->zip_postal_code = '54321';
107114
$result = $newCustomer->insertOrUpdate();
115+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
108116
$this->assertGreaterThan(0, $result);
109117
$this->assertEquals(30, $customerTable->count());
110118

@@ -172,6 +180,7 @@ public function testMultipleInserts() : void
172180
$this->assertCount(29, $customerTable);
173181

174182
$customerTable->insert($customers);
183+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
175184
$this->assertCount(32, $customerTable);
176185
$customerTable->setWhere(new \PHPFUI\ORM\Condition('zip_postal_code', operator:new \PHPFUI\ORM\Operator\IsNull()));
177186
$this->assertCount(2, $customerTable);
@@ -206,6 +215,8 @@ public function testRecordInsert() : void
206215
$table = new \Tests\App\Table\Customer();
207216
$this->assertEquals(29, $table->count());
208217
$customer->insert();
218+
// print_r(\PHPFUI\ORM::getLastSQL());
219+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
209220
$this->assertEquals(30, $table->count());
210221
$this->assertTrue($transaction->rollBack());
211222
$this->assertEquals(29, $table->count());
@@ -239,13 +250,15 @@ public function testRelatedInsert() : void
239250
$order = new \Tests\App\Record\Order();
240251
$order->employee_id = 9;
241252
$order->customer = $customer;
253+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
242254
$this->assertEquals(30, $customerTable->count());
243255
$date = \date('Y-m-d H:i:s');
244256
$order->order_date = $date;
245257
$shipper = new \Tests\App\Record\Shipper();
246258
$shipper->read(['company' => 'Shipping Company B']);
247259
$this->assertEquals(2, $shipper->shipper_id);
248260
$order->shipper = $shipper;
261+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
249262
$this->assertEquals($shipper->shipper_id, $order->shipper_id);
250263
$order->ship_name = $customer->company;
251264
$order->ship_address = $customer->address;
@@ -276,7 +289,6 @@ public function testRequiredStringNotSetInsert() : void
276289
{
277290
$test = new \Tests\App\Record\StringRecord();
278291
$id = $test->insert();
279-
$this->assertNotEmpty(\PHPFUI\ORM::getLastError());
280292
$this->assertEquals(0, $id);
281293
}
282294

@@ -286,6 +298,7 @@ public function testStringNullInsert() : void
286298
$test = new \Tests\App\Record\StringRecord();
287299
$test->stringRequired = $required = 'required';
288300
$id = $test->insert();
301+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
289302
$this->assertGreaterThan(0, $id);
290303
$insertedTest = new \Tests\App\Record\StringRecord($id);
291304
$this->assertNull($insertedTest->stringDefaultNull);

0 commit comments

Comments
 (0)