Git Product home page Git Product logo

Comments (17)

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024 1

@PejmanNik can you submit a pull request for it?

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024 1

yes you are right, adding multiple component is a better option 👍

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024

Hello nice idea!, but I think it would be better if the insert method will have an overload that takes a list of dictionaries, since the insert is an action method (where it should execute and finalize the query), in the coming version the insert method will execute the query and insert the records in the db, this why I've introduced the AsInsert method (still in dev branch)

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

Hi
Is there any progress on AsInsert overload for accepting multi-row insert?
can I help? like Laravel we can accept an array as parameter

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

@ahmad-moussawi Yes of course

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024

That's great am ready to merge when ready

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

@ahmad-moussawi Thanks.
You prefer to add multiple insert component to the query or change InsertClause class?
I suggest adding multiple insert component to the query.

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

Thanks, I am working on it.

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024

docs updated, thanks for your support
https://sqlkata.com/docs/update#insert-many
https://sqlkata.com/docs/execution/update#insert-multiple-record

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

Great 👍
Thank you for this awesome project

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

@ahmad-moussawi What do you think about to accept query object in the list for support subquery in inserting multi-record?

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024

@PejmanNik sorry I didn't catch it, do you mean passing multiple queries on insert ?

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

Thank you, Ahmad.
No. I mean something like this:

var cols = new [] {"Name", "Price"};
var subQuery = new Query("Price").Select("Amount").Limit(1);

var data = new [] {
    new object[] { "A", subQuery.Clone().Where("Name","A") },
    new object[] { "B", subQuery.Clone().Where("Name","B") },
    new object[] { "C", subQuery.Clone().Where("Name","C") },
};

var query = new Query("Products")
    .AsInsert(cols, data);

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024

mm and how it will get translated to SQL ?

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

something like this:

INSERT INTO [Products] ([Name], [Price]) 
VALUES 
 ('A', (select Top 1 Amount from Price where [Name] = 'A') ) 
, ('B', (select Top 1 Amount from Price where [Name] = 'B')),
, ('C', (select Top 1 Amount from Price where [Name] = 'C'))

It can be useful for an insert with value to foreign keys ( get from sub query )

from querybuilder.

ahmad-moussawi avatar ahmad-moussawi commented on July 19, 2024

I think it's about a very specific case, and maybe developers will get confused about it's usage, a better solution would be generating a single query that retrieve the correct results and using it once.

INSERT INTO [Products] ([Name], [Price])
SELECT [Name], [MaxPrice].[Amount] FROM [Price] JOIN [MaxPrice] ....

anyway thanks for you suggestion :)

from querybuilder.

PejmanNik avatar PejmanNik commented on July 19, 2024

You are right. I'll think of other ways to do it.
but when we talk about foreign keys (unlike to my example) it needs subquery (multi tiple fields from multi tiple table).

Thank you.

from querybuilder.

Related Issues (20)

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.