(core) Update golang dependencies

``
go get -u ./...
go mod tidy
```
Fixed SQLite related code to fit latest changes in  SQLite driver
This commit is contained in:
Alexandr Stelnykovych
2025-11-12 12:37:33 +02:00
parent 2009dcf9c8
commit f9105fc738
21 changed files with 1704 additions and 466 deletions

View File

@@ -0,0 +1,29 @@
// Code generated by BobGen sqlite v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import "context"
type contextKey string
// Relationship Contexts for records
var recordWithParentsCascadingCtx = newContextual[bool]("recordWithParentsCascading")
// Contextual is a convienience wrapper around context.WithValue and context.Value
type contextual[V any] struct {
key contextKey
}
func newContextual[V any](key string) contextual[V] {
return contextual[V]{key: contextKey(key)}
}
func (k contextual[V]) WithValue(ctx context.Context, val V) context.Context {
return context.WithValue(ctx, k.key, val)
}
func (k contextual[V]) Value(ctx context.Context) (V, bool) {
v, ok := ctx.Value(k.key).(V)
return v, ok
}

View File

@@ -0,0 +1,59 @@
// Code generated by BobGen sqlite v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"github.com/aarondl/opt/null"
models "github.com/safing/portmaster/base/database/storage/sqlite/models"
)
type Factory struct {
baseRecordMods RecordModSlice
}
func New() *Factory {
return &Factory{}
}
func (f *Factory) NewRecord(mods ...RecordMod) *RecordTemplate {
return f.NewRecordWithContext(context.Background(), mods...)
}
func (f *Factory) NewRecordWithContext(ctx context.Context, mods ...RecordMod) *RecordTemplate {
o := &RecordTemplate{f: f}
if f != nil {
f.baseRecordMods.Apply(ctx, o)
}
RecordModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingRecord(m *models.Record) *RecordTemplate {
o := &RecordTemplate{f: f, alreadyPersisted: true}
o.Key = func() string { return m.Key }
o.Format = func() null.Val[int64] { return m.Format }
o.Value = func() null.Val[[]byte] { return m.Value }
o.Created = func() int64 { return m.Created }
o.Modified = func() int64 { return m.Modified }
o.Expires = func() int64 { return m.Expires }
o.Deleted = func() int64 { return m.Deleted }
o.Secret = func() bool { return m.Secret }
o.Crownjewel = func() bool { return m.Crownjewel }
return o
}
func (f *Factory) ClearBaseRecordMods() {
f.baseRecordMods = nil
}
func (f *Factory) AddBaseRecordMod(mods ...RecordMod) {
f.baseRecordMods = append(f.baseRecordMods, mods...)
}

View File

@@ -0,0 +1,33 @@
// Code generated by BobGen sqlite v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
)
func TestCreateRecord(t *testing.T) {
if testDB == nil {
t.Skip("skipping test, no DSN provided")
}
ctx, cancel := context.WithCancel(t.Context())
t.Cleanup(cancel)
tx, err := testDB.Begin(ctx)
if err != nil {
t.Fatalf("Error starting transaction: %v", err)
}
defer func() {
if err := tx.Rollback(ctx); err != nil {
t.Fatalf("Error rolling back transaction: %v", err)
}
}()
if _, err := New().NewRecordWithContext(ctx).Create(ctx, tx); err != nil {
t.Fatalf("Error creating Record: %v", err)
}
}

View File

@@ -0,0 +1,53 @@
// Code generated by BobGen sqlite v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"strconv"
"strings"
"github.com/jaswdr/faker/v2"
)
var defaultFaker = faker.New()
func random___byte(f *faker.Faker, limits ...string) []byte {
if f == nil {
f = &defaultFaker
}
return []byte(random_string(f, limits...))
}
func random_bool(f *faker.Faker, limits ...string) bool {
if f == nil {
f = &defaultFaker
}
return f.Bool()
}
func random_int64(f *faker.Faker, limits ...string) int64 {
if f == nil {
f = &defaultFaker
}
return f.Int64()
}
func random_string(f *faker.Faker, limits ...string) string {
if f == nil {
f = &defaultFaker
}
val := strings.Join(f.Lorem().Words(f.IntBetween(1, 5)), " ")
if len(limits) == 0 {
return val
}
limitInt, _ := strconv.Atoi(limits[0])
if limitInt > 0 && limitInt < len(val) {
val = val[:limitInt]
}
return val
}

View File

@@ -0,0 +1,47 @@
// Code generated by BobGen sqlite v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"bytes"
"testing"
"github.com/stephenafamo/bob"
)
// Set the testDB to enable tests that use the database
var testDB bob.Transactor[bob.Tx]
func TestRandom___byte(t *testing.T) {
t.Parallel()
val1 := random___byte(nil)
val2 := random___byte(nil)
if bytes.Equal(val1, val2) {
t.Fatalf("random___byte() returned the same value twice: %v", val1)
}
}
func TestRandom_int64(t *testing.T) {
t.Parallel()
val1 := random_int64(nil)
val2 := random_int64(nil)
if val1 == val2 {
t.Fatalf("random_int64() returned the same value twice: %v", val1)
}
}
func TestRandom_string(t *testing.T) {
t.Parallel()
val1 := random_string(nil)
val2 := random_string(nil)
if val1 == val2 {
t.Fatalf("random_string() returned the same value twice: %v", val1)
}
}

View File

@@ -0,0 +1,629 @@
// Code generated by BobGen sqlite v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
models "github.com/safing/portmaster/base/database/storage/sqlite/models"
"github.com/stephenafamo/bob"
)
type RecordMod interface {
Apply(context.Context, *RecordTemplate)
}
type RecordModFunc func(context.Context, *RecordTemplate)
func (f RecordModFunc) Apply(ctx context.Context, n *RecordTemplate) {
f(ctx, n)
}
type RecordModSlice []RecordMod
func (mods RecordModSlice) Apply(ctx context.Context, n *RecordTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// RecordTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type RecordTemplate struct {
Key func() string
Format func() null.Val[int64]
Value func() null.Val[[]byte]
Created func() int64
Modified func() int64
Expires func() int64
Deleted func() int64
Secret func() bool
Crownjewel func() bool
f *Factory
alreadyPersisted bool
}
// Apply mods to the RecordTemplate
func (o *RecordTemplate) Apply(ctx context.Context, mods ...RecordMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.Record
// according to the relationships in the template. Nothing is inserted into the db
func (t RecordTemplate) setModelRels(o *models.Record) {}
// BuildSetter returns an *models.RecordSetter
// this does nothing with the relationship templates
func (o RecordTemplate) BuildSetter() *models.RecordSetter {
m := &models.RecordSetter{}
if o.Key != nil {
val := o.Key()
m.Key = omit.From(val)
}
if o.Format != nil {
val := o.Format()
m.Format = omitnull.FromNull(val)
}
if o.Value != nil {
val := o.Value()
m.Value = omitnull.FromNull(val)
}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.Modified != nil {
val := o.Modified()
m.Modified = omit.From(val)
}
if o.Expires != nil {
val := o.Expires()
m.Expires = omit.From(val)
}
if o.Deleted != nil {
val := o.Deleted()
m.Deleted = omit.From(val)
}
if o.Secret != nil {
val := o.Secret()
m.Secret = omit.From(val)
}
if o.Crownjewel != nil {
val := o.Crownjewel()
m.Crownjewel = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.RecordSetter
// this does nothing with the relationship templates
func (o RecordTemplate) BuildManySetter(number int) []*models.RecordSetter {
m := make([]*models.RecordSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.Record
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use RecordTemplate.Create
func (o RecordTemplate) Build() *models.Record {
m := &models.Record{}
if o.Key != nil {
m.Key = o.Key()
}
if o.Format != nil {
m.Format = o.Format()
}
if o.Value != nil {
m.Value = o.Value()
}
if o.Created != nil {
m.Created = o.Created()
}
if o.Modified != nil {
m.Modified = o.Modified()
}
if o.Expires != nil {
m.Expires = o.Expires()
}
if o.Deleted != nil {
m.Deleted = o.Deleted()
}
if o.Secret != nil {
m.Secret = o.Secret()
}
if o.Crownjewel != nil {
m.Crownjewel = o.Crownjewel()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.RecordSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use RecordTemplate.CreateMany
func (o RecordTemplate) BuildMany(number int) models.RecordSlice {
m := make(models.RecordSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableRecord(m *models.RecordSetter) {
if !(m.Key.IsValue()) {
val := random_string(nil)
m.Key = omit.From(val)
}
if !(m.Created.IsValue()) {
val := random_int64(nil)
m.Created = omit.From(val)
}
if !(m.Modified.IsValue()) {
val := random_int64(nil)
m.Modified = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.Record
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *RecordTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Record) error {
var err error
return err
}
// Create builds a record and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *RecordTemplate) Create(ctx context.Context, exec bob.Executor) (*models.Record, error) {
var err error
opt := o.BuildSetter()
ensureCreatableRecord(opt)
m, err := models.Records.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a record and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *RecordTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.Record {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a record and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *RecordTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.Record {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple records and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o RecordTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.RecordSlice, error) {
var err error
m := make(models.RecordSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple records and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o RecordTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.RecordSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple records and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o RecordTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.RecordSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// Record has methods that act as mods for the RecordTemplate
var RecordMods recordMods
type recordMods struct{}
func (m recordMods) RandomizeAllColumns(f *faker.Faker) RecordMod {
return RecordModSlice{
RecordMods.RandomKey(f),
RecordMods.RandomFormat(f),
RecordMods.RandomValue(f),
RecordMods.RandomCreated(f),
RecordMods.RandomModified(f),
RecordMods.RandomExpires(f),
RecordMods.RandomDeleted(f),
RecordMods.RandomSecret(f),
RecordMods.RandomCrownjewel(f),
}
}
// Set the model columns to this value
func (m recordMods) Key(val string) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Key = func() string { return val }
})
}
// Set the Column from the function
func (m recordMods) KeyFunc(f func() string) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Key = f
})
}
// Clear any values for the column
func (m recordMods) UnsetKey() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Key = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomKey(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Key = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m recordMods) Format(val null.Val[int64]) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Format = func() null.Val[int64] { return val }
})
}
// Set the Column from the function
func (m recordMods) FormatFunc(f func() null.Val[int64]) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Format = f
})
}
// Clear any values for the column
func (m recordMods) UnsetFormat() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Format = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m recordMods) RandomFormat(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Format = func() null.Val[int64] {
if f == nil {
f = &defaultFaker
}
val := random_int64(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m recordMods) RandomFormatNotNull(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Format = func() null.Val[int64] {
if f == nil {
f = &defaultFaker
}
val := random_int64(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m recordMods) Value(val null.Val[[]byte]) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Value = func() null.Val[[]byte] { return val }
})
}
// Set the Column from the function
func (m recordMods) ValueFunc(f func() null.Val[[]byte]) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Value = f
})
}
// Clear any values for the column
func (m recordMods) UnsetValue() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Value = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m recordMods) RandomValue(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Value = func() null.Val[[]byte] {
if f == nil {
f = &defaultFaker
}
val := random___byte(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m recordMods) RandomValueNotNull(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Value = func() null.Val[[]byte] {
if f == nil {
f = &defaultFaker
}
val := random___byte(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m recordMods) Created(val int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Created = func() int64 { return val }
})
}
// Set the Column from the function
func (m recordMods) CreatedFunc(f func() int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m recordMods) UnsetCreated() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomCreated(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Created = func() int64 {
return random_int64(f)
}
})
}
// Set the model columns to this value
func (m recordMods) Modified(val int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Modified = func() int64 { return val }
})
}
// Set the Column from the function
func (m recordMods) ModifiedFunc(f func() int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Modified = f
})
}
// Clear any values for the column
func (m recordMods) UnsetModified() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Modified = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomModified(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Modified = func() int64 {
return random_int64(f)
}
})
}
// Set the model columns to this value
func (m recordMods) Expires(val int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Expires = func() int64 { return val }
})
}
// Set the Column from the function
func (m recordMods) ExpiresFunc(f func() int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Expires = f
})
}
// Clear any values for the column
func (m recordMods) UnsetExpires() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Expires = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomExpires(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Expires = func() int64 {
return random_int64(f)
}
})
}
// Set the model columns to this value
func (m recordMods) Deleted(val int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Deleted = func() int64 { return val }
})
}
// Set the Column from the function
func (m recordMods) DeletedFunc(f func() int64) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Deleted = f
})
}
// Clear any values for the column
func (m recordMods) UnsetDeleted() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Deleted = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomDeleted(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Deleted = func() int64 {
return random_int64(f)
}
})
}
// Set the model columns to this value
func (m recordMods) Secret(val bool) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Secret = func() bool { return val }
})
}
// Set the Column from the function
func (m recordMods) SecretFunc(f func() bool) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Secret = f
})
}
// Clear any values for the column
func (m recordMods) UnsetSecret() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Secret = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomSecret(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Secret = func() bool {
return random_bool(f)
}
})
}
// Set the model columns to this value
func (m recordMods) Crownjewel(val bool) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Crownjewel = func() bool { return val }
})
}
// Set the Column from the function
func (m recordMods) CrownjewelFunc(f func() bool) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Crownjewel = f
})
}
// Clear any values for the column
func (m recordMods) UnsetCrownjewel() RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Crownjewel = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m recordMods) RandomCrownjewel(f *faker.Faker) RecordMod {
return RecordModFunc(func(_ context.Context, o *RecordTemplate) {
o.Crownjewel = func() bool {
return random_bool(f)
}
})
}
func (m recordMods) WithParentsCascading() RecordMod {
return RecordModFunc(func(ctx context.Context, o *RecordTemplate) {
if isDone, _ := recordWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = recordWithParentsCascadingCtx.WithValue(ctx, true)
})
}