Skip to content

rest-api-examples/databaseApiExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

databaseApiExample

Käytetään esimerkkiä staticApiExample pohjana ja muokataan sovellusta, niin että data haetaan tietokannasta.

  1. Luo kansio databaseApiExample
  2. Kopioi staticApiExamplen tiedostot em. kansioon
  3. Asenna MySQL moduuli komennolla
    npm install mysql2
    
  4. Luo tiedosto database.js, jossa konfiguroidaan yhteys tietokantaan
  5. Muokataan book_model.js tiedostoa, niin että data haetaan tietokannasta ja tietokantaan voidaan lisätä, muokata ja poistaa dataa

Tietokanta

Käytetään tietokantaa library ja luodaan käyttäjä tunnus seuraavalla koodilla

CREATE USER 'netuser'@'localhost' IDENTIFIED BY 'netpass';
GRANT ALL ON library.* TO 'netuser'@'localhost';

We will use the staticApiExample as a base and modify the application so that data is fetched from a database instead of a static array.
  1. Create a folder named databaseApiExample.
  2. Copy the files from **staticApiExample** into this new folder.
  3. Install the MySQL module by running the command:
    npm install mysql2
  4. Create a new file named **database.js** to configure the database connection.
  5. Modify **book_model.js** so that data is retrieved from the database, and allow adding, updating, and deleting data.

Database

We will use a database named library and create a user account with the following SQL commands:

 
CREATE USER 'netuser'@'localhost' IDENTIFIED BY 'netpass'; 
GRANT ALL ON library.* TO 'netuser'@'localhost'; 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published