Add database connexion #6

Merged
maxime.batista merged 7 commits from setup-database into master 1 year ago

This pull request adds a connection with the database, defined by the used profile.
You can see in src/index.php (on line 27) that the connexion is initialized :

$con = new Connexion(get_database());

You'll have to pass the connection object threw your gateways to do requests.

This pull request adds a connection with the database, defined by the used profile. You can see in `src/index.php` (on line 27) that the connexion is initialized : ```php $con = new Connexion(get_database()); ``` You'll have to pass the connection object threw your gateways to do requests.
maxime.batista added 6 commits 1 year ago
maxime.batista requested review from yanis.dahmane-bounoua 1 year ago
maxime.batista requested review from vivien.dufour 1 year ago
maxime.batista requested review from mael.daim 1 year ago
maxime.batista requested review from samuel.berion 1 year ago
clement.freville2 requested changes 1 year ago
ci/.drone.yml Outdated
- rsync -avz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" --delete /outputs/* iqball@maxou.dev:/server/nginx/IQBall/$DRONE_BRANCH
-
- echo "cd /server/nginx/IQBall/$DRONE_BRANCH && chmod 777 . sql" | ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev '/usr/bin/bash'
-       -
-       - echo "cd /server/nginx/IQBall/$DRONE_BRANCH && chmod 777 . sql" | ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev '/usr/bin/bash'
+       - ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev "chmod 777 /server/nginx/IQBall/$DRONE_BRANCH/sql"

```diff - - - - echo "cd /server/nginx/IQBall/$DRONE_BRANCH && chmod 777 . sql" | ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev '/usr/bin/bash' + - ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev "chmod 777 /server/nginx/IQBall/$DRONE_BRANCH/sql" ```
maxime.batista marked this conversation as resolved
export default function DisplayResults({password, username}: any) {
export default function DisplayResults({results}: { results: { name: string, description: string }[] }) {

Inlining property types makes the code not very readable, especially when it is nested.
Consider declaring the props in a separate interface or type:

interface DisplayResultsProps {
    results: readonly { name: string, description: string }[],
}
export default function DisplayResults({results}: DisplayResultsProps) {
Inlining property types makes the code not very readable, especially when it is nested. Consider declaring the props in a separate interface or type: ```ts interface DisplayResultsProps { results: readonly { name: string, description: string }[], } export default function DisplayResults({results}: DisplayResultsProps) { ```
maxime.batista marked this conversation as resolved
export default function DisplayResults({password, username}: any) {
export default function DisplayResults({results}: { results: { name: string, description: string }[] }) {
const list = results.map(({name, description}) =>
<div>

When rendering a list, each element should have a unique key to re-render the component.

When rendering a list, [each element should have a unique key](https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key) to re-render the component.
if ($req === "")
break;
$pdo->query($req);
}
- 
-             foreach (preg_split("/;\s*/", $content) as $req) {
-                 if ($req === "")
-                     break;
-                 $pdo->query($req);
-             }
+             $pdo->exec($content);
```diff - - foreach (preg_split("/;\s*/", $content) as $req) { - if ($req === "") - break; - $pdo->query($req); - } + $pdo->exec($content); ```
maxime.batista marked this conversation as resolved
sql/database.php Outdated
// in order for the touch to work
//
// Workaround in CI by setting permissions to 777 to the folder
touch(__DIR__ . "/.guard");

An alternative solution would be to ask the database its schema version.
Consider the following code:

$numberOfTables = $pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn();

If the variable is greater than zero, you know that the database has been created.

Ultimately the version is stored in the database, and dictates which migrations are required:

    try {
        $version = $pdo->query("SELECT version FROM iqball")->fetchColumn();
    } catch (PDOException $e) {
        $version = 0;
    }
An alternative solution would be to ask the database its schema version. Consider the following code: ```php $numberOfTables = $pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn(); ``` If the variable is greater than zero, you know that the database has been created. Ultimately the version is stored in the database, and dictates which migrations are required: ```php try { $version = $pdo->query("SELECT version FROM iqball")->fetchColumn(); } catch (PDOException $e) { $version = 0; } ```
maxime.batista marked this conversation as resolved
vivien.dufour approved these changes 1 year ago
maxime.batista added 1 commit 1 year ago
continuous-integration/drone/push Build is passing Details
29dd65536e
apply suggestions
mael.daim approved these changes 1 year ago
maxime.batista merged commit 7683dd2129 into master 1 year ago
maxime.batista deleted branch setup-database 1 year ago

Reviewers

samuel.berion was requested for review 1 year ago
yanis.dahmane-bounoua was requested for review 1 year ago
clement.freville2 requested changes 1 year ago
vivien.dufour approved these changes 1 year ago
mael.daim approved these changes 1 year ago
continuous-integration/drone/push Build is passing
The pull request has been merged as 7683dd2129.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: IQBall/Application-Web#6
Loading…
There is no content yet.