Skip to content

Commit 6d13e25

Browse files
committed
fix: columns map to prevent concurrent write and read
1 parent 6210ed1 commit 6d13e25

File tree

1 file changed

+5
-5
lines changed
  • drivers/sqlboiler-psql/driver

1 file changed

+5
-5
lines changed

drivers/sqlboiler-psql/driver/psql.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io/fs"
1212
"os"
1313
"strings"
14+
"sync"
1415

1516
"github.com/volatiletech/sqlboiler/v4/importers"
1617

@@ -46,7 +47,7 @@ type PostgresDriver struct {
4647
addEnumTypes bool
4748
enumNullPrefix string
4849

49-
uniqueColumns map[columnIdentifier]struct{}
50+
uniqueColumns *sync.Map
5051
configForeignKeys []drivers.ForeignKey
5152
}
5253

@@ -328,7 +329,7 @@ func (p *PostgresDriver) loadUniqueColumns() error {
328329
if p.uniqueColumns != nil {
329330
return nil
330331
}
331-
p.uniqueColumns = map[columnIdentifier]struct{}{}
332+
p.uniqueColumns = &sync.Map{}
332333
query := `with
333334
method_a as (
334335
select
@@ -375,7 +376,7 @@ select * from results;
375376
if err := rows.Scan(&c.Schema, &c.Table, &c.Column); err != nil {
376377
return errors.Wrapf(err, "unable to scan unique entry row")
377378
}
378-
p.uniqueColumns[c] = struct{}{}
379+
p.uniqueColumns.Store(c, struct{}{})
379380
}
380381
return nil
381382
}
@@ -615,8 +616,7 @@ func (p *PostgresDriver) Columns(schema, tableName string, whitelist, blacklist
615616
if err := rows.Scan(&colName, &colType, &colFullType, &udtName, &arrayType, &domainName, &defaultValue, &comment, &nullable, &generated, &identity); err != nil {
616617
return nil, errors.Wrapf(err, "unable to scan for table %s", tableName)
617618
}
618-
619-
_, unique := p.uniqueColumns[columnIdentifier{schema, tableName, colName}]
619+
_, unique := p.uniqueColumns.Load(columnIdentifier{schema, tableName, colName})
620620
column := drivers.Column{
621621
Name: colName,
622622
DBType: colType,

0 commit comments

Comments
 (0)