Skip to main content
UpsertBuilder is a tool for efficiently saving complex relational data within transactions.

UpsertBuilder Overview

Transaction Required

Always used within transactions Guarantees data consistency

UBRef References

Automatic foreign key resolution Define relationships without IDs

Sequential Saving

Save in dependency order Satisfy foreign key constraints

Type Safety

Compile-time validation Table schema verification

Basic Concept

Problems with Regular INSERT

UpsertBuilder Solution

ubRegister - Data Registration

ubRegister registers data to save and returns a UBRef.

Basic Usage

Type Safety

ubUpsert - Actual Save

ubUpsert actually saves registered data to the DB.

Basic Usage

Return Value

Save Order

Save Order Matters!Tables referenced by foreign keys must be saved first. Wrong order will cause foreign key constraint violation errors.

Practical Examples

User Registration

Create Company + Department

Create Employee (User + Employee)

UBRef Type

UBRef is a reference object, not an actual ID:

Error Handling

Transaction Rollback

Foreign Key Constraint Violation

Next Steps

Relational Data

Handle complex relationships with UBRef

Batch Operations

Bulk data registration

Advanced Patterns

Complex data structures

Transactions

Transaction detailed guide