Skip to content

Commit dd53e26

Browse files
author
James Cor
committed
field align in mem table
1 parent bc9c434 commit dd53e26

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

sql/in_mem_table/multimapeditors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func Update[V any](ctx *sql.Context, ops *ValueOps[V], is IndexedSet[V], old, ne
8989
var _ sql.TableEditor = (*IndexedSetTableEditor[string])(nil)
9090

9191
type IndexedSetTableEditor[V any] struct {
92-
Set IndexedSet[V]
9392
Ops ValueOps[V]
93+
Set IndexedSet[V]
9494
}
9595

9696
func (e *IndexedSetTableEditor[V]) StatementBegin(ctx *sql.Context) {
@@ -178,8 +178,8 @@ func MultiUpdate[V any](ctx *sql.Context, ops *MultiValueOps[V], is IndexedSet[V
178178
var _ sql.TableEditor = (*MultiIndexedSetTableEditor[string])(nil)
179179

180180
type MultiIndexedSetTableEditor[V any] struct {
181-
Set IndexedSet[V]
182181
Ops MultiValueOps[V]
182+
Set IndexedSet[V]
183183
}
184184

185185
func (e *MultiIndexedSetTableEditor[V]) StatementBegin(ctx *sql.Context) {

sql/in_mem_table/multimapeditors_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var userValueOps = ValueOps[*user]{
6363
func TestTableEditorInsert(t *testing.T) {
6464
t.Run("InsertRow", func(t *testing.T) {
6565
set := NewIndexedSet(ueq, keyers)
66-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
66+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
6767
ed.StatementBegin(nil)
6868
require.NoError(t, ed.Insert(nil, sql.Row{"aaron", "[email protected]"}))
6969
require.NoError(t, ed.StatementComplete(nil))
@@ -72,14 +72,14 @@ func TestTableEditorInsert(t *testing.T) {
7272
})
7373
t.Run("InsertDuplicateRow", func(t *testing.T) {
7474
set := NewIndexedSet(ueq, keyers)
75-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
75+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
7676
ed.StatementBegin(nil)
7777
require.NoError(t, ed.Insert(nil, sql.Row{"aaron", "[email protected]"}))
7878
require.Error(t, ed.Insert(nil, sql.Row{"aaron", "[email protected]"}))
7979
})
8080
t.Run("InsertBadSchema", func(t *testing.T) {
8181
set := NewIndexedSet(ueq, keyers)
82-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
82+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
8383
ed.StatementBegin(nil)
8484
require.Error(t, ed.Insert(nil, sql.Row{"aaron", "[email protected]", "extra value"}))
8585
require.Error(t, ed.Insert(nil, sql.Row{123, "[email protected]"}))
@@ -92,7 +92,7 @@ func TestTableEditorDelete(t *testing.T) {
9292
set := NewIndexedSet(ueq, keyers)
9393
set.Put(&user{"aaron", "[email protected]", 0})
9494
set.Put(&user{"brian", "[email protected]", 0})
95-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
95+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
9696
ed.StatementBegin(nil)
9797
require.NoError(t, ed.Delete(nil, sql.Row{"aaron", "[email protected]"}))
9898
require.NoError(t, ed.StatementComplete(nil))
@@ -103,7 +103,7 @@ func TestTableEditorDelete(t *testing.T) {
103103
set := NewIndexedSet(ueq, keyers)
104104
set.Put(&user{"aaron", "[email protected]", 0})
105105
set.Put(&user{"brian", "[email protected]", 0})
106-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
106+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
107107
ed.StatementBegin(nil)
108108
require.NoError(t, ed.Delete(nil, sql.Row{"jason", "[email protected]"}))
109109
require.NoError(t, ed.StatementComplete(nil))
@@ -115,7 +115,7 @@ func TestTableEditorDelete(t *testing.T) {
115115
set := NewIndexedSet(ueq, keyers)
116116
set.Put(&user{"aaron", "[email protected]", 0})
117117
set.Put(&user{"brian", "[email protected]", 0})
118-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
118+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
119119
ed.StatementBegin(nil)
120120
require.NoError(t, ed.Delete(nil, sql.Row{"aaron", "[email protected]"}))
121121
require.NoError(t, ed.StatementComplete(nil))
@@ -130,7 +130,7 @@ func TestTableEditorUpdate(t *testing.T) {
130130
set := NewIndexedSet(ueq, keyers)
131131
set.Put(&user{"aaron", "[email protected]", 0})
132132
set.Put(&user{"brian", "[email protected]", 0})
133-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
133+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
134134
ed.StatementBegin(nil)
135135
require.NoError(t, ed.Update(nil, sql.Row{"aaron", "[email protected]"}, sql.Row{"aaron", "[email protected]"}))
136136
require.NoError(t, ed.StatementComplete(nil))
@@ -144,7 +144,7 @@ func TestTableEditorUpdate(t *testing.T) {
144144
set := NewIndexedSet(ueq, keyers)
145145
set.Put(&user{"aaron", "[email protected]", 0})
146146
set.Put(&user{"brian", "[email protected]", 0})
147-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
147+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
148148
ed.StatementBegin(nil)
149149
require.NoError(t, ed.Update(nil, sql.Row{"aaron", "[email protected]"}, sql.Row{"aaron.son", "[email protected]"}))
150150
require.NoError(t, ed.StatementComplete(nil))
@@ -163,7 +163,7 @@ func TestTableEditorUpdate(t *testing.T) {
163163
set := NewIndexedSet(ueq, keyers)
164164
set.Put(&user{"aaron", "[email protected]", 0})
165165
set.Put(&user{"brian", "[email protected]", 1})
166-
ed := &IndexedSetTableEditor[*user]{set, userValueOps}
166+
ed := &IndexedSetTableEditor[*user]{Set: set, Ops: userValueOps}
167167
ed.StatementBegin(nil)
168168
require.NoError(t, ed.Update(nil, sql.Row{"brian", "[email protected]"}, sql.Row{"brian", "[email protected]"}))
169169
require.NoError(t, ed.StatementComplete(nil))
@@ -272,7 +272,7 @@ func TestMultiTableEditorInsert(t *testing.T) {
272272
t.Run("InsertRow", func(t *testing.T) {
273273
set := NewIndexedSet(ueq, keyers)
274274
set.Put(&user{"aaron", "[email protected]", 0})
275-
ed := &MultiIndexedSetTableEditor[*user]{set, userPetsMultiValueOps}
275+
ed := &MultiIndexedSetTableEditor[*user]{Set: set, Ops: userPetsMultiValueOps}
276276
ed.StatementBegin(nil)
277277
require.NoError(t, ed.Insert(nil, sql.Row{"aaron", "[email protected]", "dog"}))
278278
require.NoError(t, ed.Insert(nil, sql.Row{"aaron", "[email protected]", "fish"}))
@@ -288,7 +288,7 @@ func TestMultiTableEditorDelete(t *testing.T) {
288288
t.Run("DeleteRow", func(t *testing.T) {
289289
set := NewIndexedSet(ueq, keyers)
290290
set.Put(&user{"aaron", "[email protected]", userPetDog | userPetFish})
291-
ed := &MultiIndexedSetTableEditor[*user]{set, userPetsMultiValueOps}
291+
ed := &MultiIndexedSetTableEditor[*user]{Set: set, Ops: userPetsMultiValueOps}
292292
ed.StatementBegin(nil)
293293
require.NoError(t, ed.Delete(nil, sql.Row{"aaron", "[email protected]", "fish"}))
294294
require.NoError(t, ed.Delete(nil, sql.Row{"aaron", "[email protected]", "cat"}))
@@ -311,7 +311,7 @@ func TestMultiTableEditorUpdate(t *testing.T) {
311311

312312
set := NewIndexedSet(ueq, keyers)
313313
set.Put(&user{"aaron", "[email protected]", userPetDog | userPetFish})
314-
ed := &MultiIndexedSetTableEditor[*user]{set, userPetsMultiValueOps}
314+
ed := &MultiIndexedSetTableEditor[*user]{Set: set, Ops: userPetsMultiValueOps}
315315
ed.StatementBegin(nil)
316316
require.NoError(t, ed.Update(nil, sql.Row{"aaron", "[email protected]", "dog"}, sql.Row{"aaron", "[email protected]", "cat"}))
317317
require.NoError(t, ed.StatementComplete(nil))
@@ -328,7 +328,7 @@ func TestMultiTableEditorUpdate(t *testing.T) {
328328
// exist.
329329
set = NewIndexedSet(ueq, keyers)
330330
set.Put(&user{"aaron", "[email protected]", userPetDog | userPetFish})
331-
ed = &MultiIndexedSetTableEditor[*user]{set, userPetsMultiValueOps}
331+
ed = &MultiIndexedSetTableEditor[*user]{Set: set, Ops: userPetsMultiValueOps}
332332
ed.StatementBegin(nil)
333333
require.Error(t, ed.Update(nil, sql.Row{"aaron", "[email protected]", "dog"}, sql.Row{"aaron.son", "[email protected]", "cat"}))
334334

@@ -337,7 +337,7 @@ func TestMultiTableEditorUpdate(t *testing.T) {
337337
set = NewIndexedSet(ueq, keyers)
338338
set.Put(&user{"aaron", "[email protected]", userPetDog | userPetCat})
339339
set.Put(&user{"brian", "[email protected]", userPetDog})
340-
ed = &MultiIndexedSetTableEditor[*user]{set, userPetsMultiValueOps}
340+
ed = &MultiIndexedSetTableEditor[*user]{Set: set, Ops: userPetsMultiValueOps}
341341
ed.StatementBegin(nil)
342342
require.NoError(t, ed.Update(nil, sql.Row{"aaron", "[email protected]", "dog"}, sql.Row{"brian", "[email protected]", "cat"}))
343343
require.NoError(t, ed.StatementComplete(nil))

sql/in_mem_table/multimaptable.go

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,24 @@ var _ sql.ReplaceableTable = (*IndexedSetTable[string])(nil)
6666
var _ sql.TruncateableTable = (*IndexedSetTable[string])(nil)
6767

6868
type IndexedSetTable[V any] struct {
69+
ops ValueOps[V]
70+
lock sync.Locker
71+
rlock sync.Locker
6972
name string
73+
set IndexedSet[V]
7074
schema sql.Schema
7175
coll sql.CollationID
72-
73-
set IndexedSet[V]
74-
ops ValueOps[V]
75-
76-
lock sync.Locker
77-
rlock sync.Locker
7876
}
7977

8078
func NewIndexedSetTable[V any](name string, schema sql.Schema, coll sql.CollationID, set IndexedSet[V], ops ValueOps[V], lock, rlock sync.Locker) *IndexedSetTable[V] {
8179
return &IndexedSetTable[V]{
82-
name,
83-
schema,
84-
coll,
85-
set,
86-
ops,
87-
lock,
88-
rlock,
80+
name: name,
81+
schema: schema,
82+
coll: coll,
83+
set: set,
84+
ops: ops,
85+
lock: lock,
86+
rlock: rlock,
8987
}
9088
}
9189

@@ -162,8 +160,8 @@ func (t *IndexedSetTable[V]) Editor() editor {
162160
return OperationLockingTableEditor{
163161
t.lock,
164162
&IndexedSetTableEditor[V]{
165-
t.set,
166-
t.ops,
163+
Set: t.set,
164+
Ops: t.ops,
167165
},
168166
}
169167
}
@@ -175,26 +173,25 @@ var _ sql.DeletableTable = (*MultiIndexedSetTable[string])(nil)
175173
var _ sql.ReplaceableTable = (*MultiIndexedSetTable[string])(nil)
176174

177175
type MultiIndexedSetTable[V any] struct {
176+
ops MultiValueOps[V]
177+
set IndexedSet[V]
178+
lock sync.Locker
179+
rlock sync.Locker
180+
178181
name string
179182
schema sql.Schema
180183
coll sql.CollationID
181-
182-
set IndexedSet[V]
183-
ops MultiValueOps[V]
184-
185-
lock sync.Locker
186-
rlock sync.Locker
187184
}
188185

189186
func NewMultiIndexedSetTable[V any](name string, schema sql.Schema, coll sql.CollationID, set IndexedSet[V], ops MultiValueOps[V], lock, rlock sync.Locker) *MultiIndexedSetTable[V] {
190187
return &MultiIndexedSetTable[V]{
191-
name,
192-
schema,
193-
coll,
194-
set,
195-
ops,
196-
lock,
197-
rlock,
188+
name: name,
189+
schema: schema,
190+
coll: coll,
191+
set: set,
192+
ops: ops,
193+
lock: lock,
194+
rlock: rlock,
198195
}
199196
}
200197

@@ -252,8 +249,8 @@ func (t *MultiIndexedSetTable[V]) Editor() editor {
252249
return OperationLockingTableEditor{
253250
t.lock,
254251
&MultiIndexedSetTableEditor[V]{
255-
t.set,
256-
t.ops,
252+
Set: t.set,
253+
Ops: t.ops,
257254
},
258255
}
259256
}

0 commit comments

Comments
 (0)