PGlite for Ruby and Rails
Let's bring PGlite to Ruby and Rails! Enjoy using PostgreSQL without dealing with databases and native libraries—great for development and testing!
Installation
Add the gem to your Gemfile and run bundle install:
# Gemfile
gem "pglite"
Supported Ruby/Rails versions
- Ruby (MRI) >= 3.4
- Rails >= 7.2
Usage
A minimal example:
# First, you must provision the database (creates a bunch of PostgreSQL files in your file system)
PGlite.install!("tmp/pglite")
# Now you can perform queries!
result = PGLite.exec_query("SELECT 2 + 2 as answer")
result.row_count #=> 1
result.rows #=> [[4]]
result.columns.map(&:name) #=> ["answer"]
Active Record integration
Specify the pglite adapter in your database.yml. Done.
The database would be provisioned the first time a connection is initialized (in the tmp/pglite directory or in the mount_path if one is specified in the configuration). Alternatively, you can manually call PGlite.install!(path) on the application boot.
Configuration
You can enable PostgreSQL logs (stdout/stderr) by set the PGLITE_WASI_STDIO=1 environment variable.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/pglite-rb.
Credits
This gem is generated via newgem template by @palkan.
License
The gem is available as open source under the terms of the MIT License.