File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,47 @@ Then:
145145require "lustra"
146146```
147147
148+ ### Database Setup
149+
150+ Initialize your database connection:
151+
152+ ``` crystal
153+ Lustra::SQL.init("postgres://user:password@localhost/database_name")
154+ ```
155+
156+ For multiple database connections:
157+
158+ ``` crystal
159+ Lustra::SQL.init("readonly", "postgres://user:password@localhost/readonly_db")
160+ Lustra::SQL.init("primary", "postgres://user:password@localhost/primary_db")
161+ ```
162+
163+ ** Using specific connections:**
164+
165+ At the model level:
166+
167+ ``` crystal
168+ class ReadOnlyModel
169+ include Lustra::Model
170+
171+ self.connection = "readonly" # All queries use readonly connection
172+
173+ column id : Int64, primary: true
174+ column data : String
175+ end
176+ ```
177+
178+ At the query level:
179+
180+ ``` crystal
181+ # For model queries
182+ User.query.use_connection("readonly").where { active == true }
183+
184+ # For raw SQL queries
185+ Lustra::SQL.execute("readonly", "SELECT * FROM users")
186+ Lustra::SQL.select.from("users").where { active == true }.use_connection("readonly").to_a
187+ ```
188+
148189### Model definition
149190
150191Lustra offers some mixins, just include them in your classes:
You can’t perform that action at this time.
0 commit comments