
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
BetterBatch is a SQL query builder that allows upserting batches of data to a database and always getting ids in the result in the order the data was given. Using a BetterBatch query makes working with your data easier and less error prone.
The gem requires lots of information about your database to build queries. I may create better_batch-active_record
for a more streamlined interface, but you may still find this more direct example useful.
For now, only Postgres is supported.
In your Gemfile:
source 'https://rubygems.org'
gem 'better_batch'
Then:
bundle
If you're using ActiveRecord, you'll want to use better_batch-active_record.
table_name = :the_table
primary_key = :the_primary_key
input_columns = %i[column_a column_b column_c]
column_types = {
column_a: 'character varying(200)',
column_b: 'bigint',
column_c: 'text'
}
unique_columns = %i[column_b column_c]
now_on_insert = %i[created_at updated_at]
now_on_update = %i[updated_at]
returning = %i[id]
query = BetterBatch::Query.new(
table_name:,
primary_key:,
input_columns:,
column_types:,
unique_columns:,
now_on_insert:,
now_on_update:,
returning:
)
data = [
{ column_a: 'column_a data 1', column_b: 1, column_c: 'column_c data 1'},
{ column_a: 'column_a data 2', column_b: 2, column_c: 'column_c data 2'},
]
json_data = JSON.generate(data)
conn = PG.connect(dbname: 'mydb')
p conn.exec_params(query.select, [json_data]).values
p conn.exec_params(query.upsert, [json_data]).values
p conn.exec_params(query.select, [json_data]).values
Bug reports and pull requests are welcome on GitHub at https://github.com/th7/better_batch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the BetterBatch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that better_batch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.