Comments (17)
@PejmanNik can you submit a pull request for it?
from querybuilder.
yes you are right, adding multiple component is a better option 👍
from querybuilder.
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.
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.
@ahmad-moussawi Yes of course
from querybuilder.
That's great am ready to merge when ready
from querybuilder.
@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.
Thanks, I am working on it.
from querybuilder.
docs updated, thanks for your support
https://sqlkata.com/docs/update#insert-many
https://sqlkata.com/docs/execution/update#insert-multiple-record
from querybuilder.
Great 👍
Thank you for this awesome project
from querybuilder.
@ahmad-moussawi What do you think about to accept query object in the list for support subquery in inserting multi-record?
from querybuilder.
@PejmanNik sorry I didn't catch it, do you mean passing multiple queries on insert ?
from querybuilder.
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.
mm and how it will get translated to SQL ?
from querybuilder.
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.
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.
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)
- Oracle connection pooling with SqlKata
- Can you please include https://github.com/sqlkata/querybuilder/commit/f3d7c924f4d11c33056d7b002f9d5066dc856117 & re-publish 2.4.0 ?
- RobiniaDocs API Explorer
- Compile query with parameters for ODBC Connection
- Assigning NULL value to column with AsUpdate throws NotSupportedException HOT 1
- db access where day error No value given for one or more required parameters.
- [SQLServer] insert bool value #437 HOT 1
- Possible documentation error
- Distinct AsCount error
- Vulnerability in System.Text.RegularExpressions 4.3.0
- FromRaw can't translate list type parameter properly HOT 1
- how to use include HOT 2
- Question: Combining multiple Statements HOT 1
- Error on WhereContains HOT 1
- Getting Raw SQL from the package, without passing it to the database engine HOT 5
- Error when trying to insert into Always Encrypted column
- SqlServerCompiler Limit generates different query on compile compared to previous versions HOT 3
- Postgres over-escaping ? HOT 1
- `With` missing if defined in sub query HOT 2
- Use RetryProvider in SqlKata.Execution
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from querybuilder.