Skip to content

Commit

Permalink
Improve maria db
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed Dec 6, 2024
1 parent fae8fe6 commit 60d8157
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/Docker/docker-compose.yml.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ services:
ports:
- {{_config.Database.collection.mariadb.port}}:3306
volumes:
- '{{_config.App.root}}/.database/mariadb:/var/lib/mariadb'
- '{{_config.App.root}}/.database/mariadb:/var/lib/mysql'
networks:
- backend
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion src/Front/Library/Crazypartial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default abstract class Crazypartial {
* @param state:Object|null
*/
public reload = (state:Object|null = null) => {

// Check target
if(this.input.target instanceof HTMLElement && this.html !== null){

Expand Down
72 changes: 72 additions & 0 deletions src/Library/Database/Driver/Mariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CrazyPHP\Library\File\Config as FileConfig;
use CrazyPHP\Interface\CrazyDatabaseDriver;
use CrazyPHP\Exception\CrazyException;
use CrazyPHP\Library\Array\Arrays;
use Envms\FluentPDO\Query;
use PDOException;
use PDO;
Expand Down Expand Up @@ -1194,6 +1195,77 @@ public static function getConnectionArray(array $options = []):array {

}

/**
* Set Entity As Prefix
*
* @param string $entity
* @param string $alias
* @return string
*/
public static function setEntityAsPrefix(string $entity, string $alias = ""):string {

# Set result
$result = "";

# Set result exploded
$resultExploded = [];

# Open Model Config
$modelConfig = FileConfig::get("Model");

# Check current class model config exists
$modelMatching = Arrays::filterByKey($modelConfig["Model"], "name", $entity);

# Check model matching
if(!empty($modelMatching)){

# Get modelObject
$modelObject = array_pop($modelMatching);

# Get attributes
$attributes = $modelObject["attributes"] ?? [];

# Check attributes
if(!empty($attributes))

# Iteration of attributes
foreach($attributes as $attribute){

# Get currentName
$currentName = $attribute["name"] ?? "";

# Check current name
if($currentName){

# Push current name into result
$resultExploded[] =
(
$alias
? "$alias."
: ""
).$currentName.
" AS ".
$entity.
"_".
$currentName
;
}

}

}

# Check resultExploded
if(!empty($resultExploded))

# Set result
$result = implode(", ", $resultExploded);

# Return result
return $result;

}

/** Private Methods
******************************************************
*/
Expand Down
104 changes: 104 additions & 0 deletions tests/Library/Database/MariadbTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php declare(strict_types=1);
/**
* Test Database
*
* Test Database Classes
*
* PHP version 8.1.2
*
* @package kzarshenas/crazyphp
* @author kekefreedog <[email protected]>
* @copyright 2022-2024 Kévin Zarshenas
*/
namespace Tests\Library\Database;

/**
* Dependances
*/
use CrazyPHP\Library\Database\Driver\Mangodb;
use CrazyPHP\Library\Database\Driver\Mariadb;
use PHPUnit\Framework\TestCase;
use CrazyPHP\Model\Env;

/**
* Mariadb Test
*
* Methods for test Mongodb
*
* @package kzarshenas/crazyphp
* @author kekefreedog <[email protected]>
* @copyright 2022-2024 Kévin Zarshenas
*/
class MariadbTest extends TestCase {

/** Public constants
******************************************************
*/


/** Public method | Preparation
******************************************************
*/

/**
* Set Up Before Class
*
* This method is called before the first test of this test class is run.
*
* @return void
*/
public static function setUpBeforeClass():void {

# Setup env
Env::set([
# App root for composer class
"crazyphp_root" => getcwd(),
"phpunit_test" => true,
"config_location" => "@crazyphp_root/resources/Yml"
]);

}


/**
* Tear Down After Class
*
* This method is called after the last test of this test class is run.
*
* @return void
*/
public static function tearDownAfterClass():void {

# Reset env variables
Env::reset();

}

/** Public method | Tests
******************************************************
*/

/**
* Test Set Entity As Prefix
*
* Test envAndConfigValues function
*
* @return void
*/
public function testSetEntityAsPrefix():void {

# Set entity
$entity = "Router";

# Set alias
$alias = "a";

# Get result
$result = Mariadb::setEntityAsPrefix($entity, $alias);

# Check result
$this->assertEquals("a.name AS Router_name, a.path AS Router_path", $result);

}

}

0 comments on commit 60d8157

Please sign in to comment.