예제 #1
0
파일: server.py 프로젝트: ebaraniuk/labs_db
from flask import Flask, render_template, request
from main import Psql

app = Flask(__name__)
psql = Psql(input())


@app.route("/", methods=['post', 'get'])
def display_table():
    if request.method == 'POST':
        command = request.form.get('command')
        message = psql.execute_fetch(command)
        return render_template("response.html", command=command, message=message)

    table_list = psql.execute_fetch(
        "SELECT table_name FROM information_schema.tables WHERE (table_schema = 'public') ORDER BY table_name;")
    data = {}
    for table in table_list:
        table_data = psql.get_table_contents(table[0])
        data.update({table[0]: table_data})
    return render_template("main.html", data=data)


def init():
    psql.execute_file("sql/create_tables.sql")

    psql.execute_file("./sql/subject.sql")
    psql.execute_file("./sql/teachers.sql")
    psql.execute_file("./sql/clients.sql")

    print("database initialised")
예제 #2
0
파일: server.py 프로젝트: sonnyUA/labdb_1
from flask import Flask, render_template, request
import json
from pymongo import MongoClient

from main import Psql

app = Flask(__name__)

psql = Psql('1324', dbname='lab_3', user='******', host='localhost')

client = MongoClient("mongodb://*****:*****@app.route("/", methods=['post', 'get'])
def mongo_display():
    data = {}
    for collection in ("clients", "mechanics", "profession", "progress"):
        d = client["db"][collection].find({})
        data[collection] = list(d)

    return render_template("main.html", data=data)


@app.route("/postgre", methods=['post', 'get'])
def postgre_display():
    if request.method == 'POST':
        command = request.form.get('command')
        message = psql.execute_fetch(command)
        return render_template("response.html",
                               command=command,
                               message=message)
예제 #3
0
from flask import Flask, render_template, request
from main import Psql

app = Flask(__name__)

psql = Psql('postgres', dbname='lab', user='******', host='localhost')


@app.route("/", methods=['post', 'get'])
def table_display():

    if request.method == 'POST':
        command = request.form.get('command')
        print(command)
        message = psql.execute_fetch(command)
        return render_template("response.html",
                               command=command,
                               message=message)

    table_list = psql.execute_fetch(
        "SELECT table_name FROM information_schema.tables WHERE (table_schema = 'public') ORDER BY table_name;"
    )
    data = {}
    for table in table_list:

        table_data = psql.get_table_contents(table[0])
        data.update({table[0]: table_data})

    return render_template("main.html", data=data)

예제 #4
0
from main import Psql
import json

psql = Psql('mysecretpassword',
            dbname='postgres',
            user='******',
            host='localhost')

psql.execute_file("./sql_files/CREATE_TABLE.sql")
psql.execute_file("./sql_files/load_sample_data.sql")
print("database initialised")
table_list = psql.execute_fetch(
    "SELECT table_name FROM information_schema.tables WHERE (table_schema = 'public') ORDER BY table_name;"
)
data = {}
for table in table_list:
    table_data = psql.get_table_contents(table[0])
    data.update({table[0]: table_data})

print(data)
for key in data:
    l_d_ = [{data[key][0][i]: data[key][1][j][i]
             for i in range(3)} for j in range(len(data[key][1]))]
    with open(f"{key}.json", "w") as f:
        json.dump(l_d_, f)
예제 #5
0
from flask import Flask, render_template, request, redirect, url_for
from main import Psql

app = Flask(__name__)

psql = Psql('administratorpass',
                dbname='labs',
                user='******',
                host='localhost')

@app.route("/", methods=['post', 'get'])
def table_display():

    if request.method == 'POST':
        command = request.form.get('command')
        message = psql.execute(command)
        if message:
            return render_template("response.html", command = command, message = message)
        else:
            return redirect(url_for('table_display'))

    table_list = psql.execute("SELECT table_name FROM information_schema.tables WHERE (table_schema = 'public') ORDER BY table_name;")
    data = {}
    for table in table_list:

        table_data = psql.get_table_data(table[0])
        data.update({table[0]: table_data})

    return render_template("main.html", data=data)

예제 #6
0
from flask import Flask, render_template, request
import json
from pymongo import MongoClient
from main import Psql

app = Flask(__name__)

psql = Psql('vfvf3212', dbname='postgres', user='******', host='localhost')

client = MongoClient("mongodb://*****:*****@app.route("/", methods=['post', 'get'])
def mongo_display():
    data = {}
    for collection in ("orders", "films", "directors", "users"):
        d = client["db"][collection].find({})
        data[collection] = list(d)

    return render_template("main.html", data=data)


@app.route("/p", methods=['post', 'get'])
def postgre_display():
    if request.method == 'POST':
        command = request.form.get('command')
        message = psql.execute_fetch(command)
        return render_template("response.html",
                               command=command,
                               message=message)
예제 #7
0
from flask import Flask, render_template, request
from main import Psql

app = Flask(__name__)

psql = Psql('postgres',
            dbname='lab4base',
            user='******',
            host='localhost',
            port="5430")


@app.route("/", methods=['post', 'get'])
def table_display():
    if request.method == 'POST':
        command = request.form.get('command')
        message = psql.execute(command)
        return render_template("response.html",
                               command=command,
                               message=message)

    table_list = psql.execute(
        "SELECT table_name FROM information_schema.tables WHERE (table_schema = 'public') ORDER BY table_name;"
    )
    data = {}
    for table in table_list:
        table_data = psql.get_table_data(table[0])
        data.update({table[0]: table_data})

    return render_template("main.html", data=data)