Skip to content

Commit

Permalink
Basic support for insert with on conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Fs02 committed Mar 12, 2022
1 parent 6539e3b commit 54065c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/go-rel/sqlite3
go 1.16

require (
github.com/go-rel/rel v0.32.0
github.com/go-rel/sql v0.8.0
github.com/go-rel/rel v0.32.1-0.20220312033944-1afddb520d93
github.com/go-rel/sql v0.8.1-0.20220312080648-77281ca6c0f2
github.com/mattn/go-sqlite3 v1.14.10
github.com/stretchr/testify v1.7.0
)
18 changes: 4 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-rel/rel v0.28.0/go.mod h1:zaIYPmM3AfJrh0xBmm7KoVKRgTNvr0cgZfcJ88gVA2U=
github.com/go-rel/rel v0.30.0/go.mod h1:Wu6HB6x0oIiEOdUJClwmn7ByCmdL73U5gItAYObyyuo=
github.com/go-rel/rel v0.31.0/go.mod h1:fCMlDiwDSSBSoZQ6ovUyjSqS2FfpLnhwr6tW9TgnhC8=
github.com/go-rel/rel v0.32.0 h1:Y0JeQ/ZqQDB3x9QkSn8HiLtvt+5oFuYgS0tj+px59KU=
github.com/go-rel/rel v0.32.0/go.mod h1:Ulbt8kctHMw3W1JBEflFkleOk+tIqmcKHY4r1eRuNSY=
github.com/go-rel/reltest v0.4.0/go.mod h1:3udgrKCZGCMFWc8k+RH975gUdUFPE/yspG2iWN9gjqU=
github.com/go-rel/reltest v0.5.0/go.mod h1:onixPXWMVL+KILH7OdUufKDm1KN0H6FzXOP7OoNC9qM=
github.com/go-rel/reltest v0.6.0 h1:mzF49w6jo1eyvfbpogL6BvxCuJrMwsjD+49qI9gCyEs=
github.com/go-rel/reltest v0.6.0/go.mod h1:4jR+L2vn7qe6NDW1carPomp2SlbTsQ9dqkxC+n4db+k=
github.com/go-rel/sql v0.8.0 h1:RszZxejBZh9Y6dwFY81Cv1svj+9tVjaar82bwPA55Ok=
github.com/go-rel/sql v0.8.0/go.mod h1:cTFh1i1InRhZyNA43QGtQzUkzso5EFfx1BrERoXQF+0=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-rel/rel v0.32.1-0.20220312033944-1afddb520d93 h1:Bqj+8QTeAfHOrCMUUPL7ozDUjALTMr/ZbAhcFi7FCt4=
github.com/go-rel/rel v0.32.1-0.20220312033944-1afddb520d93/go.mod h1:DhB9Xmt/ymaumJAB6Z3Kq+IybLwQhhrzr6ZLeXMygPo=
github.com/go-rel/sql v0.8.1-0.20220312080648-77281ca6c0f2 h1:g6PaXs+kBVxnh2EptmGj/HyynLY9AgA5GPFxkS70XSw=
github.com/go-rel/sql v0.8.1-0.20220312080648-77281ca6c0f2/go.mod h1:u7tYWeR7tpifhb6zQ42l07MsZusrhF64q3v+yUDhBb8=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
Expand All @@ -29,8 +21,6 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
Expand Down
23 changes: 12 additions & 11 deletions sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ import (
// New sqlite3 adapter using existing connection.
func New(database *db.DB) rel.Adapter {
var (
bufferFactory = builder.BufferFactory{ArgumentPlaceholder: "?", BoolTrueValue: "1", BoolFalseValue: "0", Quoter: builder.Quote{IDPrefix: "\"", IDSuffix: "\"", IDSuffixEscapeChar: "\"", ValueQuote: "'", ValueQuoteEscapeChar: "'"}}
filterBuilder = builder.Filter{}
queryBuilder = builder.Query{BufferFactory: bufferFactory, Filter: filterBuilder}
InsertBuilder = builder.Insert{BufferFactory: bufferFactory, InsertDefaultValues: true}
insertAllBuilder = builder.InsertAll{BufferFactory: bufferFactory}
updateBuilder = builder.Update{BufferFactory: bufferFactory, Query: queryBuilder, Filter: filterBuilder}
deleteBuilder = builder.Delete{BufferFactory: bufferFactory, Query: queryBuilder, Filter: filterBuilder}
ddlBufferFactory = builder.BufferFactory{InlineValues: true, BoolTrueValue: "1", BoolFalseValue: "0", Quoter: builder.Quote{IDPrefix: "\"", IDSuffix: "\"", IDSuffixEscapeChar: "\"", ValueQuote: "'", ValueQuoteEscapeChar: "'"}}
ddlQueryBuilder = builder.Query{BufferFactory: ddlBufferFactory, Filter: filterBuilder}
tableBuilder = builder.Table{BufferFactory: ddlBufferFactory, ColumnMapper: columnMapper}
indexBuilder = builder.Index{BufferFactory: ddlBufferFactory, Query: ddlQueryBuilder, Filter: filterBuilder, SupportFilter: true}
bufferFactory = builder.BufferFactory{ArgumentPlaceholder: "?", BoolTrueValue: "1", BoolFalseValue: "0", Quoter: builder.Quote{IDPrefix: "\"", IDSuffix: "\"", IDSuffixEscapeChar: "\"", ValueQuote: "'", ValueQuoteEscapeChar: "'"}}
filterBuilder = builder.Filter{}
queryBuilder = builder.Query{BufferFactory: bufferFactory, Filter: filterBuilder}
OnConflictBuilder = builder.OnConflict{Statement: "ON CONFLICT", IgnoreStatement: "DO NOTHING", UpdateStatement: "DO UPDATE SET", TableQualifier: "EXCLUDED", SupportKey: true}
InsertBuilder = builder.Insert{BufferFactory: bufferFactory, InsertDefaultValues: true, OnConflict: OnConflictBuilder}
insertAllBuilder = builder.InsertAll{BufferFactory: bufferFactory, OnConflict: OnConflictBuilder}
updateBuilder = builder.Update{BufferFactory: bufferFactory, Query: queryBuilder, Filter: filterBuilder}
deleteBuilder = builder.Delete{BufferFactory: bufferFactory, Query: queryBuilder, Filter: filterBuilder}
ddlBufferFactory = builder.BufferFactory{InlineValues: true, BoolTrueValue: "1", BoolFalseValue: "0", Quoter: builder.Quote{IDPrefix: "\"", IDSuffix: "\"", IDSuffixEscapeChar: "\"", ValueQuote: "'", ValueQuoteEscapeChar: "'"}}
ddlQueryBuilder = builder.Query{BufferFactory: ddlBufferFactory, Filter: filterBuilder}
tableBuilder = builder.Table{BufferFactory: ddlBufferFactory, ColumnMapper: columnMapper}
indexBuilder = builder.Index{BufferFactory: ddlBufferFactory, Query: ddlQueryBuilder, Filter: filterBuilder, SupportFilter: true}
)

return &sql.SQL{
Expand Down
4 changes: 4 additions & 0 deletions sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func TestAdapter_specs(t *testing.T) {
specs.InsertBelongsTo(t, repo)
specs.Inserts(t, repo)
specs.InsertAll(t, repo)
specs.InsertOnConflictIgnore(t, repo)
specs.InsertOnConflictReplace(t, repo)
specs.InsertAllOnConflictIgnore(t, repo)
specs.InsertAllOnConflictReplace(t, repo)
// specs.InsertAllPartialCustomPrimary(t, repo) - not supported

// Update Specs
Expand Down

0 comments on commit 54065c3

Please sign in to comment.