Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
55bbb11
chore(main): release 1.1.0
github-actions[bot] Sep 29, 2025
d13abfc
Merge pull request #113 from WebFiori/release-please--branches--main
usernane Sep 29, 2025
14e9e5c
chore: Merge pull request #114 from WebFiori/dev
usernane Nov 3, 2025
8e0e4ab
chore: Merge pull request #115 from WebFiori/dev
usernane Nov 4, 2025
963743b
chore: Merge pull request #117 from WebFiori/dev
usernane Nov 4, 2025
43192d2
chore: Merge pull request #118 from WebFiori/dev
usernane Nov 5, 2025
d7ab387
chore(main): release 1.2.0
github-actions[bot] Nov 5, 2025
d48947f
chore: Merge pull request #116 from WebFiori/release-please--branches…
usernane Nov 5, 2025
9d71dd9
chore: Merge pull request #121 from WebFiori/dev
usernane Jan 6, 2026
6ce98b8
feat: Eager Loading
usernane Jan 6, 2026
d0938c6
Merge branch 'main' into feat-eager-load
usernane Jan 6, 2026
9882ed1
Merge branch 'main' into feat-eager-load
usernane Jan 6, 2026
7a441b3
docs: Eager Loading Example
usernane Jan 6, 2026
0ec584c
refactor: Table Creation Process
usernane Jan 6, 2026
2e9b53e
refactor: Drop If Exist
usernane Jan 6, 2026
fab8d4b
docs: Updated Code Samples
usernane Jan 6, 2026
ced2aeb
Update SchemaRunner.php
usernane Jan 6, 2026
bcfa585
Update MySQLQueryBuilderTest.php
usernane Jan 6, 2026
5c9a416
Update MSSQLQueryBuilderTest.php
usernane Jan 6, 2026
ebedfee
ci: Updated Workflows
usernane Jan 6, 2026
b2dfb1f
Update MSSQLQueryBuilderTest.php
usernane Jan 6, 2026
d148f94
Update php85.yaml
usernane Jan 6, 2026
3ccc426
Update php85.yaml
usernane Jan 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php81.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
code-coverage:
name: Coverage
needs: test
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@main
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@v1.2
with:
php-version: '8.1'
coverage-file: 'php-8.1-coverage.xml'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php82.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
code-coverage:
name: Coverage
needs: test
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@main
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@v1.2
with:
php-version: '8.2'
coverage-file: 'php-8.2-coverage.xml'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php83.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
code-coverage:
name: Coverage
needs: test
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@main
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@v1.2
with:
php-version: '8.3'
coverage-file: 'php-8.3-coverage.xml'
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/php84.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: php-8.4-coverage.xml
path: php-8.4-coverage.xml


code-coverage:
name: Coverage
needs: test
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@v1.2
with:
php-version: '8.4'
coverage-file: 'php-8.4-coverage.xml'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/php85.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
with:
php-version: 8.5
extensions: mysqli, mbstring, sqlsrv
tools: phpunit:11.5.27, composer
tools: phpunit:11.5.46, composer

- name: Install ODBC Driver for SQL Server
run: |
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
code-coverage:
name: Coverage
needs: test
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@main
uses: WebFiori/workflows/.github/workflows/coverage-codecov.yaml@v1.2
with:
php-version: '8.5'
coverage-file: 'php-8.5-coverage.xml'
Expand All @@ -116,13 +116,13 @@ jobs:
code-quality:
name: Code Quality
needs: test
uses: WebFiori/workflows/.github/workflows/quality-sonarcloud.yaml@main
uses: WebFiori/workflows/.github/workflows/quality-sonarcloud.yaml@v1.2
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

release-prod:
name: Prepare Production Release Branch / Publish Release
needs: [code-coverage, code-quality]
uses: WebFiori/workflows/.github/workflows/release-php.yaml@main
uses: WebFiori/workflows/.github/workflows/release-php.yaml@v1.2
with:
branch: 'main'
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## [1.2.0](https://github.com/WebFiori/database/compare/v1.1.0...v1.2.0) (2025-11-05)


### Features

* mult-results ([3c275de](https://github.com/WebFiori/database/commit/3c275de161ef4444a1242f9916d5a74a0ef2d68b))
* Multi Result Set ([8e0e4ab](https://github.com/WebFiori/database/commit/8e0e4aba4388db782b71fad95515d250b1791426))
* Multi Result Set ([8fecbf8](https://github.com/WebFiori/database/commit/8fecbf8af0d037abe75fa47f08d5140b0e4a213b))
* Parameterized Raw ([963743b](https://github.com/WebFiori/database/commit/963743bc52281948f8f88dde3c30b617fbd3535b))
* Parameterized Raw ([098285e](https://github.com/WebFiori/database/commit/098285e04e642b0b797040f7e016459393a14c3e))
* Result Set Even for Other Type of Queries ([14e9e5c](https://github.com/WebFiori/database/commit/14e9e5c20e5f6bf23b4ba050812386a2041e7d29))
* Result Set Even for Other Type of Queries ([91551c7](https://github.com/WebFiori/database/commit/91551c70abbc9c7436344cf2a0e0aa0e233c3c42))


### Miscellaneous Chores

* Configurations Update ([3705e5d](https://github.com/WebFiori/database/commit/3705e5d97782fb3318c665cff289c433c65ad682))
* Merge pull request [#114](https://github.com/WebFiori/database/issues/114) from WebFiori/dev ([14e9e5c](https://github.com/WebFiori/database/commit/14e9e5c20e5f6bf23b4ba050812386a2041e7d29))
* Merge pull request [#115](https://github.com/WebFiori/database/issues/115) from WebFiori/dev ([8e0e4ab](https://github.com/WebFiori/database/commit/8e0e4aba4388db782b71fad95515d250b1791426))
* Merge pull request [#117](https://github.com/WebFiori/database/issues/117) from WebFiori/dev ([963743b](https://github.com/WebFiori/database/commit/963743bc52281948f8f88dde3c30b617fbd3535b))
* Merge pull request [#118](https://github.com/WebFiori/database/issues/118) from WebFiori/dev ([43192d2](https://github.com/WebFiori/database/commit/43192d2d0054168a677a713ae45c7b779cb5cb85))

## [1.1.0](https://github.com/WebFiori/database/compare/v1.0.0...v1.1.0) (2025-09-29)


### Miscellaneous Chores

* Release 1.1.0 ([6389f8b](https://github.com/WebFiori/database/commit/6389f8b762c1c56eb685fecd1c7328d0a1099fe6))

## [1.0.0](https://github.com/WebFiori/database/compare/v0.10.0...v1.0.0) (2025-09-23)


Expand Down Expand Up @@ -55,4 +84,4 @@

### Bug Fixes

* Added Missing Error Code in Exception ([d8adc32](https://github.com/WebFiori/database/commit/d8adc321a6bfca7753f1c2539c391b5c12cd4795))
* Added Missing Error Code in Exception ([d8adc32](https://github.com/WebFiori/database/commit/d8adc321a6bfca7753f1c2539c391b5c12cd4795))
12 changes: 10 additions & 2 deletions WebFiori/Database/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,20 @@ public function delete() {
* the method is called on.
*
*/
public function drop() {
public function drop(bool $ifExists = false) {
$table = $this->getTable();
$this->setQuery('drop table '.$table->getName().';');
$this->setQuery($this->buildDropQuery($table->getName(), $ifExists));

return $this;
}

/**
* Builds the DROP TABLE query. Override in subclasses for DBMS-specific syntax.
*/
protected function buildDropQuery(string $tableName, bool $ifExists): string {
$ifExistsStr = $ifExists ? 'if exists ' : '';
return 'drop table ' . $ifExistsStr . $tableName . ';';
}
/**
* Constructs a query which can be used to drop a column from associated
* table.
Expand Down
7 changes: 6 additions & 1 deletion WebFiori/Database/Attributes/ForeignKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

use Attribute;

/**
* Defines a foreign key constraint and optionally a belongsTo relationship.
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class ForeignKey {
public function __construct(
Expand All @@ -11,7 +14,9 @@ public function __construct(
public array $columns = [],
public ?string $name = null,
public string $onUpdate = 'set null',
public string $onDelete = 'set null'
public string $onDelete = 'set null',
public ?string $property = null,
public ?string $entity = null
) {
if ($column !== null && !empty($columns)) {
throw new InvalidAttributeException(
Expand Down
18 changes: 18 additions & 0 deletions WebFiori/Database/Attributes/HasMany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace WebFiori\Database\Attributes;

use Attribute;

/**
* Defines a one-to-many relationship.
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class HasMany {
public function __construct(
public string $entity,
public string $foreignKey,
public string $property,
public ?string $localKey = null,
public ?string $table = null
) {}
}
32 changes: 21 additions & 11 deletions WebFiori/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,32 @@ public function createTable() : AbstractQuery {
/**
* Create SQL query which can be used to create all database tables.
*
* @return AbstractQuery The method will return an instance of the class
* 'AbstractQuery' which can be used to build SQL queries.
* Tables are created in the order they were added. On failure, any
* successfully created tables are dropped in reverse order to handle
* foreign key constraints properly.
*
* .1
* @throws DatabaseException If table creation fails.
*/
public function createTables() : AbstractQuery {
$generatedQuery = '';
public function createTables(): void {
$created = [];

foreach ($this->getTables() as $tableObj) {
if ($tableObj->getColsCount() != 0) {
$generatedQuery .= $tableObj->toSQL()."\n";
try {
foreach ($this->getTables() as $tableObj) {
if ($tableObj->getColsCount() != 0) {
$this->table($tableObj->getNormalName())->createTable()->execute();
$created[] = $tableObj;
}
}
} catch (DatabaseException $e) {
foreach (array_reverse($created) as $tableObj) {
try {
$this->table($tableObj->getNormalName())->drop()->execute();
} catch (DatabaseException $dropError) {
// Continue cleanup
}
}
throw $e;
}
$this->getQueryGenerator()->setQuery($generatedQuery, true);

return $this->getQueryGenerator();
}
/**
* Constructs a query which can be used to remove a record from the
Expand Down
7 changes: 7 additions & 0 deletions WebFiori/Database/MsSql/MSSQLQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public function __construct() {
$this->bindings = [];
}

protected function buildDropQuery(string $tableName, bool $ifExists): string {
if ($ifExists) {
return "if object_id('{$tableName}', 'U') is not null drop table {$tableName};";
}
return "drop table {$tableName};";
}

public function addBinding(Column $col, $value) {
$this->bindings[] = $value;
}
Expand Down
Loading