LoginSignup
1
0

More than 1 year has passed since last update.

Julia: Genie で MariaDB を使う

Posted at

こちらと同様のことを Genie で行いました。
Flask で MariaDB を使う
genie_mariadb.png

routes.jl
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
# --------------------------------------------------------------------
.env
user='****'
password='******'
data_base='city'

フォルダー構造

$ tree -aL 1
.
├── bin
├── bootstrap.jl
├── config
├── .env
├── .gitattributes
├── .gitignore
├── Manifest.toml
├── Project.toml
├── public
├── routes.jl
├── src
└── test
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0