Chore: Add initial/experimental xorm spanner driver (#101398)

* make it build and start

* run some migrations

* add build tags, remove log

* remove unused code

* revert go.mod changes

* move initialisation into dialect file

* update workspace

* update workspace once again

* clean up dependencies

* further cleanup

* Address some review feedback.

* Fix go.sum.

---------

Co-authored-by: Peter Štibraný <pstibrany@gmail.com>
This commit is contained in:
Serge Zaitsev
2025-03-03 17:02:10 +01:00
committed by GitHub
co-authored by Peter Štibraný
parent 4bab25054f
commit 165bca6417
32 changed files with 5144 additions and 224 deletions
+16
View File
@@ -7,6 +7,7 @@ package xorm
import (
"errors"
"fmt"
"math/rand"
"reflect"
"sort"
"strconv"
@@ -345,6 +346,21 @@ func (session *Session) innerInsert(bean any) (int64, error) {
return 0, err
}
// XXX: hack to handle autoincrement in spanner
if len(table.AutoIncrement) > 0 && session.engine.dialect.DBType() == "spanner" {
var found bool
for _, col := range colNames {
if col == table.AutoIncrement {
found = true
break
}
}
if !found {
colNames = append(colNames, table.AutoIncrement)
args = append(args, rand.Int63n(9e15))
}
}
exprs := session.statement.exprColumns
colPlaces := strings.Repeat("?, ", len(colNames))
if exprs.Len() <= 0 && len(colPlaces) > 0 {