A Ruby library for fast, database-agnostic upsert operations on MySQL, PostgreSQL, and SQLite3 without ActiveRecord dependencies.
Upsert is a Ruby library that enables efficient upsert (insert or update) operations on relational databases like MySQL, PostgreSQL, and SQLite3. It solves the problem of handling duplicate records by providing a fast, database-agnostic method that avoids the performance overhead of ActiveRecord. The library transparently creates and reuses stored procedures or functions as needed, adapting to each database's capabilities.
Ruby developers working with relational databases who need high-performance upsert operations, especially those using raw database connections (e.g., Mysql2, PG) or avoiding ActiveRecord in data-intensive applications.
Developers choose Upsert for its significant speed advantages (70–90% faster than ActiveRecord), database portability, and lightweight design without ActiveRecord dependencies. It offers a consistent API across MySQL, PostgreSQL, and SQLite3, with automatic optimization for native database features like PostgreSQL's ON CONFLICT.
Upsert on MySQL, PostgreSQL, and SQLite3. Transparently creates functions (UDF) for MySQL and PostgreSQL; on SQLite3, uses INSERT OR IGNORE.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Benchmarked 70-90% faster than ActiveRecord upsert emulations, with batch mode adding further optimization for bulk operations.
Works across MySQL, PostgreSQL, and SQLite3 on both MRI and JRuby, transparently handling database-specific SQL implementations.
No ActiveRecord dependency; uses raw connections like Mysql2::Client, reducing overhead for non-Rails or performance-focused apps.
Automatically uses INSERT ON CONFLICT on PostgreSQL 9.5+ when unique constraints exist, leveraging database-native features for speed.
Native upsert requires unique constraints, not indexes, which can be a schema hurdle and forces fallback to slower user-defined functions if missing.
Lacks data type conversion, causing errors like inserting strings into integer columns, as noted in PostgreSQL examples requiring manual handling.
Requires clearing generated stored procedures/functions manually with custom code, adding operational complexity and potential for leftover artifacts.