ankpan18 commited on
Commit
d6a5921
·
1 Parent(s): db013e7

sql commands

Browse files
Files changed (5) hide show
  1. Dockerfile +2 -1
  2. app.py +21 -0
  3. index.html +22 -0
  4. requirements.txt +2 -0
  5. test.sql +9 -0
Dockerfile CHANGED
@@ -35,7 +35,8 @@ RUN pip install -r requirements.txt
35
 
36
  RUN echo "hello"
37
  CMD python3 -c "print('Docker is more simple Deployment Tool')"
38
- # CMD mysql -h localhost -u root
 
39
  # CMD source test.sql
40
 
41
 
 
35
 
36
  RUN echo "hello"
37
  CMD python3 -c "print('Docker is more simple Deployment Tool')"
38
+
39
+ CMD mysql -h localhost -u root && show databases;
40
  # CMD source test.sql
41
 
42
 
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template
2
+ import pymysql
3
+
4
+ app = Flask(__name__)
5
+
6
+ db = pymysql.connect(
7
+ host="db",
8
+ user="user",
9
+ password="password",
10
+ database="mysqldb"
11
+ )
12
+
13
+ @app.route("/")
14
+ def index():
15
+ cursor = db.cursor()
16
+ cursor.execute("SELECT * FROM users")
17
+ data = cursor.fetchall()
18
+ return render_template("index.html", data=data)
19
+
20
+ if __name__ == "__main__":
21
+ app.run(host="0.0.0.0", port=5000)
index.html ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ <title>Flask App with MySQL</title>
4
+ </head>
5
+ <body>
6
+ <h1>Users</h1>
7
+ <table>
8
+ <tr>
9
+ <th>ID</th>
10
+ <th>Name</th>
11
+ <th>Email</th>
12
+ </tr>
13
+ {% for row in data %}
14
+ <tr>
15
+ <td>{{ row[0] }}</td>
16
+ <td>{{ row[1] }}</td>
17
+ <td>{{ row[2] }}</td>
18
+ </tr>
19
+ {% endfor %}
20
+ </table>
21
+ </body>
22
+ </html>
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Flask==2.0.2
2
+ pymysql==1.0.2
test.sql ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ CREATE TABLE users (
2
+ id INT PRIMARY KEY,
3
+ name VARCHAR(255),
4
+ email VARCHAR(255)
5
+ );
6
+
7
+ INSERT INTO users VALUES (1, 'Alice', 'alice@example.com');
8
+ INSERT INTO users VALUES (2, 'Bob', 'bob@example.com');
9
+ INSERT INTO users VALUES (3, 'Charlie', 'charlie@example.com');