Module: Libsql
- Defined in:
- lib/libsql.rb
Defined Under Namespace
Classes: Connection, Database, QueryResult
Class Method Summary collapse
-
.connect_with_env ⇒ Object
Helper method to create a database connection using .env credentials.
Class Method Details
.connect_with_env ⇒ Object
Helper method to create a database connection using .env credentials
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/libsql.rb', line 139 def self.connect_with_env Dotenv.load # Check for required environment variables unless ENV['TURSO_DATABASE_URL'] && ENV['TURSO_AUTH_TOKEN'] raise "Missing TURSO_DATABASE_URL or TURSO_AUTH_TOKEN in .env file" end db = Database.new( url: ENV['TURSO_DATABASE_URL'], auth_token: ENV['TURSO_AUTH_TOKEN'] ) # If a block is given, yield connection if block_given? db.connect { |conn| yield conn } else db end end |