2025-02-05 14:18:02 +08:00
|
|
|
|
from flask import Flask, render_template, request, jsonify
|
|
|
|
|
from utils.sql_parse import parse_create_table_sql
|
|
|
|
|
from utils.log import Log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
2025-02-05 16:16:44 +08:00
|
|
|
|
log = Log().getlog()
|
2025-02-05 14:18:02 +08:00
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
|
def index():
|
|
|
|
|
return render_template('index.html')
|
|
|
|
|
|
|
|
|
|
@app.route('/convert', methods=['POST'])
|
|
|
|
|
def convert_sql():
|
2025-02-05 16:16:44 +08:00
|
|
|
|
|
2025-02-05 14:18:02 +08:00
|
|
|
|
sql_input = request.form['sql']
|
2025-02-07 17:09:31 +08:00
|
|
|
|
if sql_input.strip()=='':
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
'parsed_result': "请在上面输入框输入hologres建表语句",
|
|
|
|
|
'message': 'SQL processed.'
|
|
|
|
|
})
|
|
|
|
|
|
2025-02-05 14:18:02 +08:00
|
|
|
|
hologres_connection = request.form['hologresConnection']
|
|
|
|
|
log.info("SQL Input: %s", sql_input)
|
|
|
|
|
log.info("SQL hologres_connection: %s", hologres_connection)
|
|
|
|
|
try:
|
|
|
|
|
parsed_result=parse_create_table_sql(sql_input,hologres_connection)
|
|
|
|
|
result = {
|
2025-02-05 15:57:40 +08:00
|
|
|
|
'parsed_result': parsed_result,
|
2025-02-05 14:18:02 +08:00
|
|
|
|
'message': 'SQL processed successfully.'
|
|
|
|
|
}
|
|
|
|
|
except Exception as e:
|
2025-02-05 15:57:40 +08:00
|
|
|
|
result = {'error': f'请检查输入sql:\n\n {str(e)}'}
|
2025-02-05 14:18:02 +08:00
|
|
|
|
log.info("SQL result: %s", result)
|
|
|
|
|
return jsonify(result)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
# 指定host和port,这里使用0.0.0.0可以让服务器被外部访问
|
2025-02-05 15:57:40 +08:00
|
|
|
|
app.run(host='0.0.0.0', port=8777, debug=True)
|