Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ public function getModelName(): string
return $this->modelName;
}

/**
* @inheritDoc
*/
public function truncate(): bool
{
try {
$this->getOrmModel()->raw_execute("DELETE FROM {$this->table}");
return true;
} catch (\Exception $e) {
return false;
}
}

/**
* @param ORM $ormModel
*/
Expand Down
16 changes: 8 additions & 8 deletions src/Libraries/Database/Adapters/Sleekdb/SleekDbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ public function updateOrmModel(?array $modelData)
}

/**
* Deletes the table and the data
* @throws BaseException
* @throws DatabaseException
* @throws IOException
* @throws InvalidArgumentException
* @throws InvalidConfigurationException
* @inheritdoc
*/
public function deleteTable()
public function truncate(): bool
{
$this->getOrmModel()->deleteStore();
try {
$this->getOrmModel()->deleteStore();
return true;
} catch (\Exception $e) {
return false;
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/Libraries/Database/Contracts/DbalInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function criterias(...$criterias): DbalInterface;
* @param string|null $value
* @return DbalInterface
*/
public function having(string $column, string $operator, string $value = null): DbalInterface;
public function having(string $column, string $operator, ?string $value = null): DbalInterface;

/**
* Groups the result by given column
Expand Down Expand Up @@ -171,6 +171,12 @@ public function save(): bool;
*/
public function delete(): bool;

/**
* Deletes all records from the table
* @return bool
*/
public function truncate(): bool;

/**
* Deletes many records by previously applied criteria
* @return bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class AuthService extends QtService implements AuthServiceInterface
*/
public function deleteAllUsers()
{
$this->model->deleteTable();
$this->model->truncate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CommentService extends QtService
*/
public function deleteAllComments()
{
$this->model->deleteTable();
$this->model->truncate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class PostService extends QtService
*/
public function deleteAllPost()
{
$this->model->deleteTable();
$this->model->truncate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class AuthService extends QtService implements AuthServiceInterface
*/
public function deleteAllUsers()
{
$this->model->deleteTable();
$this->model->truncate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CommentService extends QtService
*/
public function deleteAllComments()
{
$this->model->deleteTable();
$this->model->truncate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class PostService extends QtService
*/
public function deleteAllPosts()
{
$this->model->deleteTable();
$this->model->truncate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function deleteTables(): void
{
foreach ($this->tables as $table) {
$model = new SleekDbal($table);
$model->deleteTable();
$model->truncate();
}
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Model/ModelSoftDeletesSleek.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setUp(): void

public function tearDown(): void
{
ModelFactory::get(TestProductsModel::class)->deleteTable();
ModelFactory::get(TestProductsModel::class)->truncate();
}

public function testSleekDeleteSetsDeletedAt()
Expand Down