4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

直接SQLでconfig指定以外のDBアクセスをする

4
Last updated at Posted at 2018-01-25

config/*.exsに指定する接続先DB以外のDBも、普通にselectできる

	def a(), do: "select * from a.users" |> query
	def b(), do: "select * from b.users" |> query
	def query( sql ) when sql != "" do
		{ :ok, result } = Ecto.Adapters.SQL.query( Livery.Repo, sql, [] )
		result
	end

なので、こんな感じでDB指定する関数化もできる

	def users( db ), do: "select * from #{ db }.users" |> query
	def query( sql ) when sql != "" do
		{ :ok, result } = Ecto.Adapters.SQL.query( Livery.Repo, sql, [] )
		result
	end

これとマルチプロセスやFlowをうまく組み合わせると、簡単な並行DBアクセスくらいは作れそう

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?