Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf3cb74b

Browse files
committed
use_multiple_databases (issue#27)
1 parentc081720 commitf3cb74b

File tree

12 files changed

+288
-260
lines changed

12 files changed

+288
-260
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ before_script:
5353
-psql -U postgres -tc 'SHOW server_version'
5454
-psql -U postgres -c '\conninfo'
5555
-psql -c "CREATE DATABASE postgresqltest;" -U postgres
56+
-psql -c "CREATE DATABASE postgresqltest2;" -U postgres
5657

5758
# ODBC
5859
-if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install mysql; brew services start mysql; fi

‎src/Backends/Hive.jl‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@ module HiveLoader
44
using Hive# HiveSession HiveAuth
55
using Octo.Repo: SQLKeyword, ExecuteResult
66

7-
const current=Dict{Symbol, Any}(
8-
:sess=>nothing,
9-
)
10-
11-
current_sess()= current[:sess]
7+
# db_dbname
8+
functiondb_dbname(nt::NamedTuple)::String
9+
""
10+
end
1211

1312
# db_connect
1413
functiondb_connect(; host::String="localhost", port::Integer=10000, auth::HiveAuth=HiveAuth(), tprotocol::Symbol=:binary)
15-
sess=HiveSession(host, port, auth; tprotocol=tprotocol)
16-
current[:sess]= sess
14+
HiveSession(host, port, auth; tprotocol=tprotocol)
1715
end
1816

1917
# db_disconnect
20-
functiondb_disconnect()
21-
sess=current_sess()
18+
functiondb_disconnect(sess)
2219
if sessisa HiveSession
2320
Hive.close(sess)
24-
current[:sess]=nothing
2521
end
2622
end
2723

2824
# query
29-
functionquery(sql::String)
30-
sess=current_sess()
25+
functionquery(sess, sql::String)
3126
pending= Hive.execute(sess, sql)
3227
rs= Hive.result(pending)
3328
sch= Hive.schema(rs)
@@ -38,27 +33,26 @@ function query(sql::String)
3833
nts
3934
end
4035

41-
functionquery(prepared::String, vals::Vector)# throw UnsupportedError
36+
functionquery(sess,prepared::String, vals::Vector)# throw UnsupportedError
4237
throw(UnsupportedError("needs to be implemented"))
4338
end
4439

4540
# execute
46-
functionexecute(sql::String)::ExecuteResult
47-
sess=current_sess()
41+
functionexecute(sess, sql::String)::ExecuteResult
4842
result= Hive.execute(sess, sql)
4943
ExecuteResult()
5044
end
5145

52-
functionexecute(prepared::String, vals::Vector)::ExecuteResult# throw UnsupportedError
46+
functionexecute(sess,prepared::String, vals::Vector)::ExecuteResult# throw UnsupportedError
5347
throw(UnsupportedError("needs to be implemented"))
5448
end
5549

56-
functionexecute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult# throw UnsupportedError
50+
functionexecute(sess,prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult# throw UnsupportedError
5751
throw(UnsupportedError("needs to be implemented"))
5852
end
5953

6054
# execute_result
61-
functionexecute_result(command::SQLKeyword)::ExecuteResult
55+
functionexecute_result(sess,command::SQLKeyword)::ExecuteResult
6256
ExecuteResult()
6357
end
6458

‎src/Backends/JDBC.jl‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ using DataFrames: DataFrame
66
using Octo.Repo: SQLKeyword, ExecuteResult
77
using Octo.Backends: UnsupportedError
88

9-
const current=Dict{Symbol, Any}(
10-
:conn=>nothing,
11-
)
12-
13-
current_conn()= current[:conn]
9+
# db_dbname
10+
functiondb_dbname(nt::NamedTuple)::String
11+
nt.connection.url
12+
end
1413

1514
# db_connect
1615
functiondb_connect(; kwargs...)
@@ -23,14 +22,12 @@ function db_connect(; kwargs...)
2322
props=Dict([string.(kv)for kvin opts])
2423
conn= JDBC.DriverManager.getConnection(url, props)
2524
end
26-
current[:conn]=conn
25+
conn
2726
end
2827

2928
# db_disconnect
30-
functiondb_disconnect()
31-
conn=current_conn()
29+
functiondb_disconnect(conn)
3230
JDBC.close(conn)
33-
current[:conn]=nothing
3431
end
3532

3633
functionVector{<:NamedTuple}(df::DataFrame)
@@ -40,8 +37,7 @@ function Vector{<:NamedTuple}(df::DataFrame)
4037
end
4138

4239
# query
43-
functionquery(sql::String)
44-
conn=current_conn()
40+
functionquery(conn, sql::String)
4541
stmt= JDBC.createStatement(conn)
4642
rs= JDBC.executeQuery(stmt, sql)
4743
df= JDBC.load(DataFrame, rs)
@@ -75,31 +71,27 @@ function prepared_execute(conn, prepared::String, vals::Vector)
7571
n
7672
end
7773

78-
functionquery(prepared::String, vals::Vector)
79-
conn=current_conn()
74+
functionquery(conn, prepared::String, vals::Vector)
8075
rs=prepared_execute(conn, prepared, vals)
8176
df= JDBC.load(DataFrame, rs)
8277
JDBC.close(rs)
8378
Vector{<:NamedTuple}(df)
8479
end
8580

8681
# execute
87-
functionexecute(sql::String)::ExecuteResult
88-
conn=current_conn()
82+
functionexecute(conn, sql::String)::ExecuteResult
8983
stmt= JDBC.createStatement(conn)
9084
n= JDBC.executeUpdate(stmt, sql)
9185
JDBC.close(stmt)
9286
ExecuteResult()
9387
end
9488

95-
functionexecute(prepared::String, vals::Vector)::ExecuteResult
96-
conn=current_conn()
89+
functionexecute(conn, prepared::String, vals::Vector)::ExecuteResult
9790
n=prepared_execute(conn, prepared, vals)
9891
ExecuteResult()
9992
end
10093

101-
functionexecute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
102-
conn=current_conn()
94+
functionexecute(conn, prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
10395
for tupin nts
10496
vals=collect(tup)
10597
n=prepared_execute(conn, prepared, vals)
@@ -108,7 +100,7 @@ function execute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
108100
end
109101

110102
# execute_result
111-
functionexecute_result(command::SQLKeyword)::ExecuteResult
103+
functionexecute_result(conn,command::SQLKeyword)::ExecuteResult
112104
ExecuteResult()
113105
end
114106

‎src/Backends/MySQL.jl‎

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,47 @@ using Octo.Repo: SQLKeyword, ExecuteResult
88
using Octo.AdapterBase: INSERT
99
using Octo.Backends: UnsupportedError
1010

11-
const current=Dict{Symbol, Any}(
12-
:conn=>nothing,
13-
)
14-
15-
current_conn()= current[:conn]
11+
# db_dbname
12+
functiondb_dbname(nt::NamedTuple)::String
13+
get(nt,:db,"")
14+
end
1615

1716
# db_connect
1817
functiondb_connect(; kwargs...)
1918
args= (:hostname,:username,:password)
2019
(hostname, username, password)=getindex.(Ref(kwargs), args)
2120
options=filter(kv->!(kv.firstin args), kwargs)
22-
conn= DBInterface.connect(MySQL.Connection, hostname, username, password; options...)
23-
current[:conn]= conn
21+
DBInterface.connect(MySQL.Connection, hostname, username, password; options...)
2422
end
2523

2624
# db_disconnect
27-
functiondb_disconnect()
28-
conn=current_conn()
25+
functiondb_disconnect(conn)
2926
DBInterface.close!(conn)
30-
current[:conn]=nothing
3127
end
3228

3329
# query
34-
functionquery(sql::String)
35-
conn=current_conn()
30+
functionquery(conn, sql::String)
3631
(Tables.rowtable DBInterface.execute)(conn, sql)
3732
end
3833

39-
functionquery(prepared::String, vals::Vector)
40-
conn=current_conn()
34+
functionquery(conn, prepared::String, vals::Vector)
4135
stmt= DBInterface.prepare(conn, prepared)
4236
(Tables.rowtable DBInterface.execute)(stmt, vals)
4337
end
4438

4539
# execute
46-
functionexecute(sql::String)::ExecuteResult
47-
conn=current_conn()
40+
functionexecute(conn, sql::String)::ExecuteResult
4841
DBInterface.execute(conn, sql)
4942
ExecuteResult()
5043
end
5144

52-
functionexecute(prepared::String, vals::Vector)::ExecuteResult
53-
conn=current_conn()
45+
functionexecute(conn, prepared::String, vals::Vector)::ExecuteResult
5446
stmt= DBInterface.prepare(conn, prepared)
5547
DBInterface.execute(stmt, vals)
5648
ExecuteResult()
5749
end
5850

59-
functionexecute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
60-
conn=current_conn()
51+
functionexecute(conn, prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
6152
stmt= DBInterface.prepare(conn, prepared)
6253
for ntin nts
6354
DBInterface.execute(stmt,values(nt))
@@ -66,9 +57,8 @@ function execute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
6657
end
6758

6859
# execute_result
69-
functionexecute_result(command::SQLKeyword)::ExecuteResult
60+
functionexecute_result(conn,command::SQLKeyword)::ExecuteResult
7061
if INSERT=== command
71-
conn=current_conn()
7262
last_insert_id= MySQL.API.insertid(conn.mysql)
7363
(id=last_insert_id,)
7464
end

‎src/Backends/ODBC.jl‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,47 @@ using ODBC # 1.0
77
using.ODBC.DBInterface
88
using.ODBC.Tables
99

10-
const current=Dict{Symbol, Any}(
11-
:conn=>nothing,
12-
)
13-
14-
current_conn()= current[:conn]
10+
# db_dbname
11+
functiondb_dbname(nt::NamedTuple)::String
12+
""
13+
end
1514

1615
# db_connect
1716
functiondb_connect(; kwargs...)
1817
if!isempty(kwargs)
1918
dsn=get(kwargs,:dsn,"")
20-
conn= DBInterface.connect(ODBC.Connection, dsn)
21-
current[:conn]= conn
19+
DBInterface.connect(ODBC.Connection, dsn)
2220
end
2321
end
2422

2523
# db_disconnect
26-
functiondb_disconnect()
27-
conn=current_conn()
24+
functiondb_disconnect(conn)
2825
DBInterface.close!(conn)
29-
current[:conn]=nothing
3026
end
3127

3228
# query
33-
functionquery(sql::String)
34-
conn=current_conn()
29+
functionquery(conn, sql::String)
3530
(Tables.rowtable DBInterface.execute)(conn, sql)
3631
end
3732

38-
functionquery(prepared::String, vals::Vector)
39-
conn=current_conn()
33+
functionquery(conn, prepared::String, vals::Vector)
4034
stmt= DBInterface.prepare(conn, prepared)
4135
(Tables.rowtable DBInterface.execute)(stmt, vals)
4236
end
4337

4438
# execute
45-
functionexecute(sql::String)::ExecuteResult
46-
conn=current_conn()
39+
functionexecute(conn, sql::String)::ExecuteResult
4740
DBInterface.execute(conn, sql)
4841
ExecuteResult()
4942
end
5043

51-
functionexecute(prepared::String, vals::Vector)::ExecuteResult
52-
conn=current_conn()
44+
functionexecute(conn, prepared::String, vals::Vector)::ExecuteResult
5345
stmt= DBInterface.prepare(conn, prepared)
5446
DBInterface.execute(stmt, vals)
5547
ExecuteResult()
5648
end
5749

58-
functionexecute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
59-
conn=current_conn()
50+
functionexecute(conn, prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
6051
stmt= DBInterface.prepare(conn, prepared)
6152
for ntin nts
6253
DBInterface.execute(stmt,values(nt))
@@ -65,7 +56,7 @@ function execute(prepared::String, nts::Vector{<:NamedTuple})::ExecuteResult
6556
end
6657

6758
# execute_result
68-
functionexecute_result(command::SQLKeyword)::ExecuteResult
59+
functionexecute_result(conn,command::SQLKeyword)::ExecuteResult
6960
ExecuteResult()
7061
end
7162

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp