Code Monkey home page Code Monkey logo

flexlabs.upsert's Introduction

FlexLabs.Upsert

Build status FlexLabs.EntityFrameworkCore.Upsert on NuGet
CI build: FlexLabs.EntityFrameworkCore.Upsert on MyGet

This library adds basic support for "Upsert" operations to EF Core.

Uses INSERT … ON CONFLICT DO UPDATE in PostgreSQL/Sqlite, MERGE in SqlServer and INSERT INTO … ON DUPLICATE KEY UPDATE in MySQL.

Also supports injecting sql command runners to add support for other providers

A typical upsert command could look something like this:

DataContext.DailyVisits
    .Upsert(new DailyVisit
    {
        UserID = userID,
        Date = DateTime.UtcNow.Date,
        Visits = 1,
    })
    .On(v => new { v.UserID, v.Date })
    .WhenMatched(v => new DailyVisit
    {
        Visits = v.Visits + 1,
    })
    .RunAsync();

In this case, the upsert command will ensure that a new DailyVisit will be added to the database. If a visit with the same UserID and Date already exists, it will be updated by incrementing it's Visits value by 1.

Please read our Usage page for more examples

flexlabs.upsert's People

Contributors

artiomchi avatar longhronshen avatar apiwt avatar grante avatar frankchen021 avatar bbrandt avatar obea avatar romangolovanov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.