Skip to content

Close #238, support batch insert.#285

Merged
jmoiron merged 2 commits intojmoiron:masterfrom
hmgle:batch-insert
Mar 19, 2019
Merged

Close #238, support batch insert.#285
jmoiron merged 2 commits intojmoiron:masterfrom
hmgle:batch-insert

Conversation

@hmgle
Copy link
Copy Markdown
Contributor

@hmgle hmgle commented Feb 25, 2017

usage:
places := []*Place{&place1, &place2}
db.NamedExec("INSERT INTO place (country, telcode) VALUES (:country, :telcode)", places)

usage:
places := []*Place{&place1, &place2}
db.NamedExec("INSERT INTO place (country, telcode) VALUES (:country, :telcode)", places)
@dcormier
Copy link
Copy Markdown

I would be great to see this added and close #238.

@dcormier dcormier mentioned this pull request Aug 10, 2018
@AndyEsser
Copy link
Copy Markdown

Would also be very useful for us

@branch-divy
Copy link
Copy Markdown

+1

@venkateshthallam
Copy link
Copy Markdown

+1. We could really use this.

@aceyin
Copy link
Copy Markdown

aceyin commented Sep 7, 2018

when this feature will be released ?

mfateev pushed a commit to mfateev/sqlx that referenced this pull request Sep 10, 2018
@Seklfreak
Copy link
Copy Markdown

+1 would be very useful

@kohpai
Copy link
Copy Markdown

kohpai commented Oct 23, 2018

Would be a great feature to have

@mfateev
Copy link
Copy Markdown

mfateev commented Oct 23, 2018

+1. Waiting on this. In the meantime I have to use a private fork :(.

@mCloud
Copy link
Copy Markdown

mCloud commented Nov 17, 2018

++

@xurwxj
Copy link
Copy Markdown

xurwxj commented Nov 19, 2018

+1

1 similar comment
@safety-tom
Copy link
Copy Markdown

+1

@ivanovaleksey
Copy link
Copy Markdown

@jmoiron Hi, do you have any plans for this feature?

@god1dog
Copy link
Copy Markdown

god1dog commented Nov 25, 2018

we waiting this feature!

@pawanrawal
Copy link
Copy Markdown

Can we please at least know if there is something else needed to get this merged @jmoiron?

@matyunin
Copy link
Copy Markdown

matyunin commented Dec 6, 2018

Waiting for merge PLZ 🙏

1 similar comment
@TomohiroYamada
Copy link
Copy Markdown

Waiting for merge PLZ 🙏

@renskiy
Copy link
Copy Markdown

renskiy commented Dec 27, 2018

@hmgle this is great feature but it missed some tests, do you have plans to add them?

@arushijn
Copy link
Copy Markdown

+1 need this feature

@polym
Copy link
Copy Markdown

polym commented Feb 18, 2019

+1

@GnatorX
Copy link
Copy Markdown

GnatorX commented Feb 20, 2019

+1 any update on merging this feature?

@ductm54
Copy link
Copy Markdown

ductm54 commented Feb 27, 2019

+1

1 similar comment
@tonyOreglia
Copy link
Copy Markdown

+1

@gayanhewa
Copy link
Copy Markdown

Is this likely to get merged? Or is the approach recommended by @tanishiking in #238 the recommended way to go?

@jmoiron
Copy link
Copy Markdown
Owner

jmoiron commented Mar 12, 2019

I like this approach, I will merge it and bump version on sqlx as soon as I can look over this and test it.

@gayanhewa
Copy link
Copy Markdown

@jmoiron Awesome, can lend a hand with the testing if required.

@gayanhewa
Copy link
Copy Markdown

gayanhewa commented Mar 21, 2019

This is how I used it with NamedExec, not much different.

        processedTxns := []*salesTxn{}
        // append a bunch
        // ...

	if len(processedTxns) > 0 {
		tx := pulseDB.MustBegin()
		sql = "INSERT INTO sales_transactions(id, company_id, mobileuser_id) VALUES (:id, :company_id, :mobileuser_id)"
		if _, err := tx.NamedExec(sql, processedTxns); err != nil {
			fmt.Printf("Failed updating sales transactions for mobileuser %s \n", m.ID)
			log.Println(err)
		}
		tx.Commit()
	}

@cgebe
Copy link
Copy Markdown

cgebe commented Apr 4, 2019

I had problems passing a list of referenced structs which caused sqlx to insert only 1 record without error. Passing non-referenced structs works as usual. I used a local SQLite DB.

@hejiaji
Copy link
Copy Markdown

hejiaji commented May 6, 2019

@jmoiron Is this feature going to be published with a tag on anytime soon?

@smartfly
Copy link
Copy Markdown

good function

@WiredTombstone
Copy link
Copy Markdown

WiredTombstone commented Jun 16, 2019

Unfortunately I get this error: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1.

Does anyone have a recommendation for debugging this? (The SQL does work if I do a for over the records and execute it individually, but does not work if I pass all the records).

Looking into it a bit it might be because my Insert statement looks like this:

INSERT INTO table (IP) VALUES (INET6_ATON(:IP))

Edit Update: Altering the regex on line 213 of named.go to be ([^(]?+[^)].) seems to resolve my issue, though it may not be advisable as a patch for everyone.

@valclark1
Copy link
Copy Markdown

When is this going to be released? I tried using it in 1.2.0 but I keep getting a Mapping slice error.

@gosom
Copy link
Copy Markdown

gosom commented Aug 21, 2019

Also using 1.2.0 and getting the same
jmoiron/sqlx/reflectx.(*Mapper).TraversalsByNameFunc on slice Value

@un000
Copy link
Copy Markdown

un000 commented Sep 7, 2019

the same @jmoiron

@haynesherway
Copy link
Copy Markdown

same

@griddyphillip
Copy link
Copy Markdown

also here @jmoiron

@griddyphillip
Copy link
Copy Markdown

for anybody looking for a hotfix, it's likely that your go.mod isn't pointing to the master branch and pointed to v1.2.0

try running go get github.com/jmoiron/sqlx@master to fix this

@franzwilhelm
Copy link
Copy Markdown

Still getting the slice value error on master with postgres

@sepbot
Copy link
Copy Markdown

sepbot commented Dec 5, 2019

Doesn't seem to work when slice values are map[string]interface{}, it wants struct

@coolyrat
Copy link
Copy Markdown

coolyrat commented Mar 1, 2020

hoping to release soon

@tshubham7
Copy link
Copy Markdown

after doing this
go get github.com/jmoiron/sqlx@master
I can insert multiple records at one time, thanks

@dmngu9
Copy link
Copy Markdown

dmngu9 commented Aug 3, 2020

do you have example on how to do batch insert ?

@dcormier
Copy link
Copy Markdown

dcormier commented Aug 3, 2020

@dmngu9 The example is in the opening comment on this PR. Just scroll to the top.

@dmitrychopey
Copy link
Copy Markdown

Hello. When are you planing to release this feature?

@riptl
Copy link
Copy Markdown

riptl commented Dec 13, 2020

@dmitrychopey If you need this and don't want to wait for a release, use go get github.com/jmoiron/sqlx@master to tell Go to use the latest commit.

@MarceloVano
Copy link
Copy Markdown

is it broken? I'm facing the same issue with latest commit, version v1.3.4-0.20210409010340-1810e7a2e72d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.