朱莉娅:在Genie上使用MariaDB

genie_mariadb.png
using Genie.Router
using MySQL
using DotEnv
# --------------------------------------------------------------------
function mariadb_read_proc()
    DotEnv.config()
    user=ENV["user"]
    password=ENV["password"]
    data_base=ENV["data_base"]

    conn =DBInterface.connect(MySQL.Connection, "127.0.0.1", user, password)
    command = "select * from " * data_base * ".cities;"
    stmt = DBInterface.prepare(conn,command)
    results = DBInterface.execute(stmt)
    rowid = DBInterface.lastrowid(results)
    str_out = ""
    for row in results
        str_out *= row[1] * '\t' * row[2] * '\t'
        str_out *= string(row[3]) * '\t' * string(row[4]) * '\n'
    end
#
    DBInterface.close!(stmt)
    DBInterface.close!(conn)
    str_out
end
# --------------------------------------------------------------------
route("/") do
  serve_static_file("welcome.html")
end

route("/mariadb") do
    str_out = "<pre>"
    str_out *= mariadb_read_proc()
    str_out *= "</pre>"
end
# --------------------------------------------------------------------
user='****'
password='******'
data_base='city'

文件夹结构

$ tree -aL 1
.
├── bin
├── bootstrap.jl
├── config
├── .env
├── .gitattributes
├── .gitignore
├── Manifest.toml
├── Project.toml
├── public
├── routes.jl
├── src
└── test
广告
将在 10 秒后关闭
bannerAds