GithubHelp home page GithubHelp logo

compa85 / datahub Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 211 KB

Applicazione Php e React per la gestione di un database

Home Page: https://datahub.compalab.dev

License: GNU General Public License v3.0

PHP 39.24% Dockerfile 0.38% JavaScript 59.15% HTML 0.52% CSS 0.72%

datahub's Introduction

DataHub

DataHub è una web application, sviluppata a scopo didattico, che consente di eseguire le principali operazioni di CRUD (Create, Read, Update, Delete) su un database, attraverso richieste e risposte in formato JSON.

Tecnologie utilizzate

  • Frontend: React
  • Backend: Php
  • Database: MariaDB

Configurazione

Requisiti

Assicurati di avere installato Docker sul tuo sistema prima di continuare.

Installazione

Dopo aver clonato il repository con:

git clone https://github.com/compa85/DataHub.git

esegui i seguenti comandi:

cd DataHub
docker compose up -d

DataHub è ora in esecuzione su http://localhost:3000

Se vuoi testare unicamente la parte di backend vai a http://localhost:3001

Per accedere invece a phpmyadmin vai a http://localhost:3002

Api

Le API che permettono di interagire con il database si trovano all'indirizzo http://localhost:3001/api e sono le seguenti:

  • select.php
  • insert.php
  • update.php
  • delete.php
  • getcolumns.php
  • getlastid.php
  • gettables.php
  • execquery.php

Json

Richiesta

La struttura del JSON può variare a seconda della query che si desidera eseguire. Di seguito sono riportati i vari esempi.

Ogni JSON deve contenere una o più tabelle del database, rappresentate come un attributo dell'oggetto principale.

Select

L'array corrispondente al nome della tabella, contiene gli oggetti che rappresentano i criteri per individuare i record da restituire. Si consiglia di utilizzare le chiavi primarie per identificare i record da restituire.

Se l'array dovesse essere vuoto, tutti i record della tabella verranno restituiti.

{
   "orders": [
      {
         "id": "17",
      }
   ]
}

Con questo JSON vengono restituiti i dettagli dell'ordine con id 17.

Insert

Per ogni tabella, vi è un array di oggetti, i quali rappresentano i record da inserire.

All'interno di ciascun oggetto, sono definiti i campi che costituiscono i record del database. Ogni campo è rappresentato da una coppia di chiave-valore, dove la chiave corrisponde al nome del campo e il valore è il dato da inserire.

Per evitare errori, assicurati che all'interno della stessa tabella ogni oggetto da inserire abbia gli stessi attributi.

{
   "customers": [
      {
         "first_name": "John",
         "last_name": "Doe",
         "email": "[email protected]"
      },
      {
         "first_name": "Jane",
         "last_name": "Smith",
         "email": "[email protected]"
      }
   ]
}

Con questo JSON vengono aggiunti due nuovi clienti John e Jane.

Update

L'array corrispondente al nome della tabella contiene uno o più sottoarray che rappresentano i record da aggiornare. Ciascun sottoarray deve contenere due oggetti:

  1. Il primo contiene i campi da usare come criteri di ricerca per individuare i record da aggiornare.
  2. Il secondo contiene i campi da aggiornare con i nuovi valori desiderati.
{
   "customers": [
      [
         {
            "id": "47"
         },
         {
            "email": "[email protected]"
         }
      ]
   ]
}

Con questo JSON viene aggiornata l'email del cliente con id 47.

Delete

L'array corrispondente al nome della tabella, contiene gli oggetti che rappresentano i criteri per individuare i record da eliminare. Si consiglia di utilizzare le chiavi primarie per identificare i record da eliminare.

Se l'array dovesse essere vuoto, tutti i record della tabella verranno eliminati.

{
   "orders": [
      {
         "id": "31",
      },
      {
         "date": "2024-01-01"
      }
   ]
}

Con questo JSON viene eliminato l'ordine con id 31 e vengono eliminati anche tutti gli ordini effettutati in data 2024-01-01.

GetColumns

L'array tables, contiene i nomi delle tabelle delle quali verranno restituiti i dettagli delle colonne da cui sono formate.

{
   "tables": [ "orders", "orderdetails" ]
}

Con questo JSON viene restituito { Field: "orderNumber", Type: "int(11)", Null: "NO", Key: "PRI", Default: "NULL", Extra: "" }, ... .

GetLastId

L'array tables, contiene i nomi delle tabelle da cui verranno restituiti i valori massimi delle chiavi primarie.

{
   "tables": [ "orders", "offices" ]
}

Con questo JSON viene restituito "31" e "7".

GetTables

Non ha parametri e restituisce i nomi delle tabelle del database.

ExecQuery

L'array queries, contiene le query da eseguire.

{
   "queries": [ "SELECT id FROM orders WHERE id = 31", "SELECT officeCode FROM offices WHERE officeCode = 1" ]
}

Con questo JSON viene restituito "31" e "1".

Risposta

Il seguente JSON rappresenta un esempio di risposta fornita in seguito ad un'operazione di select.

{
   "status": "ok",
   "message": "2 records selected",
   "query": ["SELECT * FROM customers"],
   "result": [
      [
         {"first_name": "Mario", "last_name": "Rossi"},
         {"first_name": "Giovanni", "last_name": "Verdi"}
      ]
   ]
}
  • status (string) → riporta se l'esecuzione dell'operazione è andata a buon fine o meno: "ok" se è stata completata con successo o "error" se si è verificato un errore
  • message (string) → riporta delle informazioni aggiuntive sull'esito delle operazioni eseguite
  • query (array) → riporta le query eseguite
  • result (array) → riporta i risultati delle query

In determinate query o in caso di errore, gli attributi query e result possono assumere il valore di null.

datahub's People

Contributors

compa85 avatar pej073 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.