<<「ユーザーは多くのデータベースを持っていますか」という質問とも呼ばれます。>>
環境
私のアプリは次のようにモデル化されています:
user has_many databases
database has_many tables
table has_many rows
row habtm(+value) columns
あなたはアイデアを得る!
したがって、データベース内でデータベースをモデル化する代わりに、次のものが必要です。
- ユーザーを保持する sqlite3 データベースと
- ユーザーごとに多数の sqlite データベース
各ユーザーはデータベース内のテーブルを LCRUD します (phpmyadmin と同様)。
問題
データベース接続と table_name のスレッドセーフなリクエストごとの構成が必要です
class Table < ActiveRecord::Base
end
# in some controller
# set the connection to the user-selected database from some DB list
Table.connection = current_user.session.connection
# set the name to the user-selected table from some tables list
Table.table_name = params[:table_name]
@rows = Table.all #display them
EDIT
ご覧のとおり、接続はグローバルでスレッド間で共有されますが、私のアプリの仕様によると、各ユーザーには独自の接続があります。ここで、2 人の異なるユーザーが同時に 2 つのリクエストを行ったとします。
オプション?
- ActiveRecord をあきらめて、必要最小限の DB ドライバーを使用する
- スレッドセーフをあきらめる