Merge pull request 'db_testdata' (#21) from db_testdata into develop

Reviewed-on: #21
This commit is contained in:
Fabian 2025-02-27 10:18:36 +00:00
commit 6e1deb2612
11 changed files with 184 additions and 32 deletions

3
.gitignore vendored
View File

@ -104,7 +104,6 @@ dist
# vuepress v2.x temp and cache directory # vuepress v2.x temp and cache directory
.temp .temp
.cache
# Docusaurus cache and generated files # Docusaurus cache and generated files
.docusaurus .docusaurus
@ -132,3 +131,5 @@ dist
.pnp.* .pnp.*
/.idea/git_toolbox_blame.xml /.idea/git_toolbox_blame.xml
.package.json
.package-lock.json

View File

@ -1,10 +1,10 @@
CREATE TABLE `discount` CREATE TABLE `discount`
( (
`deleted_at` INT(8) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NOT NULL, `description` TEXT NOT NULL,
`discount_percent` DECIMAL(8, 2) NOT NULL, `discount_percent` DECIMAL(8, 2) NOT NULL,
`deleted_at` INT(8) NOT NULL,
`modified_at` INT(8) NOT NULL, `modified_at` INT(8) NOT NULL,
`created_at` INT(8) NOT NULL, `created_at` INT(8) NOT NULL,
`active` BOOLEAN NOT NULL `active` BOOLEAN NOT NULL
@ -101,16 +101,16 @@ CREATE TABLE `product_category`
); );
CREATE TABLE `user` CREATE TABLE `user`
( (
`is_active` BOOLEAN NOT NULL, `is_active` BOOLEAN NOT NULL DEFAULT '1',
`lower_name` VARCHAR(255) NOT NULL, `lower_name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL DEFAULT 'NONE',
`passwd_hash_algo` VARCHAR(255) NOT NULL, `passwd_hash_algo` VARCHAR(255) NOT NULL DEFAULT 'NONE',
`modified_at` INT(8) NOT NULL, `modified_at` INT(8) NOT NULL DEFAULT '0',
`is_admin` BOOLEAN NOT NULL, `is_admin` BOOLEAN NOT NULL DEFAULT '0',
`name` VARCHAR(255) NOT NULL, `name` VARCHAR(255) NOT NULL,
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`created_at` INT(8) NOT NULL, `created_at` INT(8) NOT NULL DEFAULT '0',
`passwd` VARCHAR(255) NOT NULL `passwd` VARCHAR(255) NOT NULL DEFAULT 'NONE'
); );
ALTER TABLE ALTER TABLE
`user` `user`

View File

@ -20,5 +20,4 @@ drop table if exists user;
drop table if exists user_address; drop table if exists user_address;
drop table if exists user_payment; drop table if exists user_payment;

View File

@ -0,0 +1,15 @@
CREATE PROCEDURE fill_user_table()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE emailString CHAR(16) DEFAULT 'test';
DELETE FROM webshop.user;
WHILE i < 100
DO
SET emailString = CONCAT(emailString, CAST(i AS CHAR(16)), '@test.de');
INSERT INTO webshop.user(is_active, name, lower_name, email)
VALUES ('1', 'harry', 'potter', emailString);
SET i = i + 1;
END WHILE;
END;

View File

@ -1,17 +0,0 @@
const mysql = require('mysql');
const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "webshop"
});
connection.connect(function (err) {
if (err) throw err;
console.log("Connected to database");
connection.query("SELECT * FROM user", function (err, result) {
if (err) throw err;
console.log(result);
})
});

122
package-lock.json generated
View File

@ -13,6 +13,7 @@
"express": "^4.21.2", "express": "^4.21.2",
"express-session": "^1.18.1", "express-session": "^1.18.1",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"mysql2": "^3.12.0",
"path": "^0.12.7" "path": "^0.12.7"
} }
}, },
@ -33,6 +34,15 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
}, },
"node_modules/aws-ssl-profiles": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
"integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==",
"license": "MIT",
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/bignumber.js": { "node_modules/bignumber.js": {
"version": "9.0.0", "version": "9.0.0",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
@ -151,6 +161,15 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/denque": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.10"
}
},
"node_modules/depd": { "node_modules/depd": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@ -343,6 +362,15 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/generate-function": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
"license": "MIT",
"dependencies": {
"is-property": "^1.0.2"
}
},
"node_modules/get-intrinsic": { "node_modules/get-intrinsic": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
@ -455,11 +483,47 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/is-property": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==",
"license": "MIT"
},
"node_modules/isarray": { "node_modules/isarray": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
}, },
"node_modules/long": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz",
"integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==",
"license": "Apache-2.0"
},
"node_modules/lru-cache": {
"version": "7.18.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/lru.min": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.1.tgz",
"integrity": "sha512-FbAj6lXil6t8z4z3j0E5mfRlPzxkySotzUHwRXjlpRh10vc6AI6WN62ehZj82VG7M20rqogJ0GLwar2Xa05a8Q==",
"license": "MIT",
"engines": {
"bun": ">=1.0.0",
"deno": ">=1.30.0",
"node": ">=8.0.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wellwelwel"
}
},
"node_modules/media-typer": { "node_modules/media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@ -538,6 +602,59 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
}, },
"node_modules/mysql2": {
"version": "3.12.0",
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.12.0.tgz",
"integrity": "sha512-C8fWhVysZoH63tJbX8d10IAoYCyXy4fdRFz2Ihrt9jtPILYynFEKUUzpp1U7qxzDc3tMbotvaBH+sl6bFnGZiw==",
"license": "MIT",
"dependencies": {
"aws-ssl-profiles": "^1.1.1",
"denque": "^2.1.0",
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.3",
"long": "^5.2.1",
"lru.min": "^1.0.0",
"named-placeholders": "^1.1.3",
"seq-queue": "^0.0.5",
"sqlstring": "^2.3.2"
},
"engines": {
"node": ">= 8.0"
}
},
"node_modules/mysql2/node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/mysql2/node_modules/sqlstring": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz",
"integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/named-placeholders": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz",
"integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==",
"license": "MIT",
"dependencies": {
"lru-cache": "^7.14.1"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/negotiator": { "node_modules/negotiator": {
"version": "0.6.3", "version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
@ -747,6 +864,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
}, },
"node_modules/seq-queue": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz",
"integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q=="
},
"node_modules/serve-static": { "node_modules/serve-static": {
"version": "1.16.2", "version": "1.16.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz",

View File

@ -15,6 +15,7 @@
"express": "^4.21.2", "express": "^4.21.2",
"express-session": "^1.18.1", "express-session": "^1.18.1",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"mysql2": "^3.12.0",
"path": "^0.12.7" "path": "^0.12.7"
} }
} }

View File

@ -2,7 +2,7 @@
APP_PORT=3000 APP_PORT=3000
# configuration for db access # configuration for db access
DB_HOST=172.0.0.1:3306 DB_HOST=localhost
DB_USER=root DB_USER=root
DB_PASSWORD= DB_PASSWORD=
DB_DATABASE= DB_DATABASE=webshop

View File

@ -1,5 +1,7 @@
const mysql = require('mysql2'); const mysql = require('mysql2');
require('dotenv').config({path:'process.env'}); require('dotenv').config({path: 'C:/Daten/Webshop/process.env'});
//to-do: '.env' Dateien aus anderen Directories aufrufen ohne absoluten Pfad
// require("dotenv").config({path:'C:/Daten/Webshop/process.env'})
const connection = mysql.createConnection({ const connection = mysql.createConnection({
host : process.env.DB_HOST, host : process.env.DB_HOST,

12
scripts/modules/login.js Normal file
View File

@ -0,0 +1,12 @@
require('mysql2')
let userInput = "test1"
let appRoot = require('app-root-path')
let dbConnect = require(appRoot + '/scripts/modules/db-connect.js')
dbConnect.query("SELECT * FROM webshop.user WHERE email = " + "'" + userInput + "'", function (err, result) {
if (err) throw err
console.log(result)
})
dbConnect.end()

View File

@ -0,0 +1,17 @@
const mysql = require('mysql');
const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "webshop"
})
connection.connect(function (err) {
if (err) throw err
console.log("Connected to database")
connection.query("SELECT * FROM webshop.user WHERE ID = 15", function (err, result) {
if (err) throw err
console.log(result)
})
})