Skip to content

danielmhanover/typeorm-upsert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeORM Upsert

Say you have a TypeORM entity Post and you want to atomically upsert:

import { Upsert } from 'typeorm-upsert'
import { SnakeCase } from 'snake-case'


const post: Post = { ... }

(async () => {
    const upserted_post = await Upsert(
        Post, 
        post,
        "id",   // primary-key to upsert on
        
        // optional params
        {
            key_naming_transform: SnakeCase, // arbitrarily transform keys before UPSERT
            do_not_upsert: ['created_at']    // exclude non-nullable keys from UPDATE that are required in the event of an INSERT operation
        }
    )
    
    console.log(upserted_post) // prints the finished version of `Post`
})

Tested with PostgreSQL 9.5+. Contributors welcome.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published