Upgrade goext

This commit is contained in:
Mike Schwörer 2024-05-31 23:56:16 +02:00
parent d5d89ee93a
commit 7553e1f51e
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
28 changed files with 210 additions and 466 deletions

View File

@ -8,18 +8,27 @@
- [ ] Channel List - [ ] Channel List
* [ ] Show subs * [ ] Show subs
* [ ] CRUD * [ ] CRUD
* [ ] what about unsubbed foreign channels? - thex should still be visible (or should they, do i still get the messages?)
- [ ] Sub List - [ ] Sub List
* [ ] Sub/Unsub/Accept/Deny * [ ] Sub/Unsub/Accept/Deny
- [ ] Debug List (Show logs, requests) - [ ] Debug List (Show logs, requests)
- [ ] Key List - [ ] Key List
* [ ] CRUD * [ ] CRUD
- [ ] Auto R-only key for admin, use for QR+link - [ ] Auto R-only key for admin, use for QR+link+send
- [ ] settings - [ ] settings
- [ ] notifications - [ ] notifications
- [ ] push navigation stack - [ ] push navigation stack
- [ ] read + migrate old SharedPrefs - [ ] read + migrate old SharedPrefs (or not? - who uses SCN even??)
- [ ] Account-Page - [ ] Account-Page
- [ ] Logout - [ ] Logout
- [ ] Send-page - [ ] Send-page
-----
- [ ] Switch server to sq style from faby
- [ ] switch from mattn to go-sqlite
- [ ] Single struct for model/db/json
- [ ] use sq.Query | sq.Update | sq.InsertAndQuery | ....
- [ ] sq.DBOptions - enable CommentTrimmer and DefaultConverter
- [ ] run unit-tests...

View File

@ -11,6 +11,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"gogs.mikescher.com/BlackForestBytes/goext/dataext" "gogs.mikescher.com/BlackForestBytes/goext/dataext"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"math/rand"
"runtime/debug" "runtime/debug"
"time" "time"
) )
@ -60,7 +61,7 @@ func Wrap(rlacc RequestLogAcceptor, fn WHandlerFunc) gin.HandlerFunc {
panic(err) panic(err)
} }
time.Sleep(retrySleep) time.Sleep(time.Duration(int64(float64(retrySleep) * (0.5 + rand.Float64()))))
continue continue
} }
@ -174,8 +175,14 @@ func resetBody(g *gin.Context) error {
func isSqlite3Busy(r HTTPResponse) bool { func isSqlite3Busy(r HTTPResponse) bool {
if errwrap, ok := r.(*errorHTTPResponse); ok && errwrap != nil { if errwrap, ok := r.(*errorHTTPResponse); ok && errwrap != nil {
if s3err, ok := (errwrap.error).(sqlite3.Error); ok {
if s3err.Code == sqlite3.ErrBusy { if errors.Is(errwrap.error, sqlite3.ErrBusy) {
return true
}
var s3err sqlite3.Error
if errors.As(errwrap.error, &s3err) {
if errors.Is(s3err.Code, sqlite3.ErrBusy) {
return true return true
} }
} }

View File

@ -75,7 +75,7 @@ func (pp *DBPreprocessor) Init(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
resrows1, err := sq.ScanAll[tabInfo](rows1, sq.SModeFast, sq.Unsafe, true) resrows1, err := sq.ScanAll[tabInfo](ctx, pp.db, rows1, sq.SModeFast, sq.Unsafe, true)
if err != nil { if err != nil {
return err return err
} }
@ -85,7 +85,7 @@ func (pp *DBPreprocessor) Init(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
resrows2, err := sq.ScanAll[colInfo](rows2, sq.SModeFast, sq.Unsafe, true) resrows2, err := sq.ScanAll[colInfo](ctx, pp.db, rows2, sq.SModeFast, sq.Unsafe, true)
if err != nil { if err != nil {
return err return err
} }

View File

@ -42,7 +42,7 @@ func NewLogsDatabase(cfg server.Config) (*Database, error) {
xdb.SetConnMaxIdleTime(60 * time.Minute) xdb.SetConnMaxIdleTime(60 * time.Minute)
} }
qqdb := sq.NewDB(xdb) qqdb := sq.NewDB(xdb, sq.DBOptions{})
if conf.EnableLogger { if conf.EnableLogger {
qqdb.AddListener(dbtools.DBLogger{}) qqdb.AddListener(dbtools.DBLogger{})

View File

@ -23,7 +23,7 @@ func (db *Database) GetChannelByName(ctx db.TxContext, userid models.UserID, cha
return nil, err return nil, err
} }
channel, err := models.DecodeChannel(rows) channel, err := models.DecodeChannel(ctx, tx, rows)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, nil return nil, nil
} }
@ -47,7 +47,7 @@ func (db *Database) GetChannelByID(ctx db.TxContext, chanid models.ChannelID) (*
return nil, err return nil, err
} }
channel, err := models.DecodeChannel(rows) channel, err := models.DecodeChannel(ctx, tx, rows)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, nil return nil, nil
} }
@ -108,7 +108,7 @@ func (db *Database) ListChannelsByOwner(ctx db.TxContext, userid models.UserID,
return nil, err return nil, err
} }
data, err := models.DecodeChannelsWithSubscription(rows) data, err := models.DecodeChannelsWithSubscription(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -138,7 +138,7 @@ func (db *Database) ListChannelsBySubscriber(ctx db.TxContext, userid models.Use
return nil, err return nil, err
} }
data, err := models.DecodeChannelsWithSubscription(rows) data, err := models.DecodeChannelsWithSubscription(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -169,7 +169,7 @@ func (db *Database) ListChannelsByAccess(ctx db.TxContext, userid models.UserID,
return nil, err return nil, err
} }
data, err := models.DecodeChannelsWithSubscription(rows) data, err := models.DecodeChannelsWithSubscription(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -203,7 +203,7 @@ func (db *Database) GetChannel(ctx db.TxContext, userid models.UserID, channelid
return models.ChannelWithSubscription{}, err return models.ChannelWithSubscription{}, err
} }
channel, err := models.DecodeChannelWithSubscription(rows) channel, err := models.DecodeChannelWithSubscription(ctx, tx, rows)
if err != nil { if err != nil {
return models.ChannelWithSubscription{}, err return models.ChannelWithSubscription{}, err
} }

View File

@ -56,7 +56,7 @@ func (db *Database) ListClients(ctx db.TxContext, userid models.UserID) ([]model
return nil, err return nil, err
} }
data, err := models.DecodeClients(rows) data, err := models.DecodeClients(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -78,7 +78,7 @@ func (db *Database) GetClient(ctx db.TxContext, userid models.UserID, clientid m
return models.Client{}, err return models.Client{}, err
} }
client, err := models.DecodeClient(rows) client, err := models.DecodeClient(ctx, tx, rows)
if err != nil { if err != nil {
return models.Client{}, err return models.Client{}, err
} }

View File

@ -42,7 +42,7 @@ func NewPrimaryDatabase(cfg server.Config) (*Database, error) {
xdb.SetConnMaxIdleTime(60 * time.Minute) xdb.SetConnMaxIdleTime(60 * time.Minute)
} }
qqdb := sq.NewDB(xdb) qqdb := sq.NewDB(xdb, sq.DBOptions{})
if conf.EnableLogger { if conf.EnableLogger {
qqdb.AddListener(dbtools.DBLogger{}) qqdb.AddListener(dbtools.DBLogger{})

View File

@ -82,7 +82,7 @@ func (db *Database) ListRetrieableDeliveries(ctx db.TxContext, pageSize int) ([]
return nil, err return nil, err
} }
data, err := models.DecodeDeliveries(rows) data, err := models.DecodeDeliveries(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -49,7 +49,7 @@ func (db *Database) ListKeyTokens(ctx db.TxContext, ownerID models.UserID) ([]mo
return nil, err return nil, err
} }
data, err := models.DecodeKeyTokens(rows) data, err := models.DecodeKeyTokens(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -71,7 +71,7 @@ func (db *Database) GetKeyToken(ctx db.TxContext, userid models.UserID, keyToken
return models.KeyToken{}, err return models.KeyToken{}, err
} }
keyToken, err := models.DecodeKeyToken(rows) keyToken, err := models.DecodeKeyToken(ctx, tx, rows)
if err != nil { if err != nil {
return models.KeyToken{}, err return models.KeyToken{}, err
} }
@ -90,7 +90,7 @@ func (db *Database) GetKeyTokenByToken(ctx db.TxContext, key string) (*models.Ke
return nil, err return nil, err
} }
user, err := models.DecodeKeyToken(rows) user, err := models.DecodeKeyToken(ctx, tx, rows)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, nil return nil, nil
} }

View File

@ -21,7 +21,7 @@ func (db *Database) GetMessageByUserMessageID(ctx db.TxContext, usrMsgId string)
return nil, err return nil, err
} }
msg, err := models.DecodeMessage(rows) msg, err := models.DecodeMessage(ctx, tx, rows)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, nil return nil, nil
} }
@ -50,7 +50,7 @@ func (db *Database) GetMessage(ctx db.TxContext, scnMessageID models.MessageID,
return models.Message{}, err return models.Message{}, err
} }
msg, err := models.DecodeMessage(rows) msg, err := models.DecodeMessage(ctx, tx, rows)
if err != nil { if err != nil {
return models.Message{}, err return models.Message{}, err
} }
@ -138,7 +138,7 @@ func (db *Database) ListMessages(ctx db.TxContext, filter models.MessageFilter,
return nil, ct.CursorToken{}, err return nil, ct.CursorToken{}, err
} }
data, err := models.DecodeMessages(rows) data, err := models.DecodeMessages(ctx, tx, rows)
if err != nil { if err != nil {
return nil, ct.CursorToken{}, err return nil, ct.CursorToken{}, err
} }

View File

@ -50,7 +50,7 @@ func (db *Database) ListSubscriptions(ctx db.TxContext, filter models.Subscripti
return nil, err return nil, err
} }
data, err := models.DecodeSubscriptions(rows) data, err := models.DecodeSubscriptions(ctx, tx, rows)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -69,7 +69,7 @@ func (db *Database) GetSubscription(ctx db.TxContext, subid models.SubscriptionI
return models.Subscription{}, err return models.Subscription{}, err
} }
sub, err := models.DecodeSubscription(rows) sub, err := models.DecodeSubscription(ctx, tx, rows)
if err != nil { if err != nil {
return models.Subscription{}, err return models.Subscription{}, err
} }
@ -91,7 +91,7 @@ func (db *Database) GetSubscriptionBySubscriber(ctx db.TxContext, subscriberId m
return nil, err return nil, err
} }
user, err := models.DecodeSubscription(rows) user, err := models.DecodeSubscription(ctx, tx, rows)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, nil return nil, nil
} }

View File

@ -61,7 +61,7 @@ func (db *Database) GetUser(ctx db.TxContext, userid models.UserID) (models.User
return models.User{}, err return models.User{}, err
} }
user, err := models.DecodeUser(rows) user, err := models.DecodeUser(ctx, tx, rows)
if err != nil { if err != nil {
return models.User{}, err return models.User{}, err
} }

View File

@ -42,7 +42,7 @@ func NewRequestsDatabase(cfg server.Config) (*Database, error) {
xdb.SetConnMaxIdleTime(60 * time.Minute) xdb.SetConnMaxIdleTime(60 * time.Minute)
} }
qqdb := sq.NewDB(xdb) qqdb := sq.NewDB(xdb, sq.DBOptions{})
if conf.EnableLogger { if conf.EnableLogger {
qqdb.AddListener(dbtools.DBLogger{}) qqdb.AddListener(dbtools.DBLogger{})
@ -92,7 +92,7 @@ func (db *Database) Migrate(outerctx context.Context) error {
schemastr := schema.RequestsSchema[schema.RequestsSchemaVersion].SQL schemastr := schema.RequestsSchema[schema.RequestsSchemaVersion].SQL
schemahash := schema.RequestsSchema[schema.RequestsSchemaVersion].Hash schemahash := schema.RequestsSchema[schema.RequestsSchemaVersion].Hash
schemahash, err := sq.HashSqliteSchema(tctx, schemastr) schemahash, err := sq.HashMattnSqliteSchema(tctx, schemastr)
if err != nil { if err != nil {
return err return err
} }

View File

@ -78,7 +78,7 @@ func (db *Database) ListRequestLogs(ctx context.Context, filter models.RequestLo
return nil, ct.CursorToken{}, err return nil, ct.CursorToken{}, err
} }
data, err := models.DecodeRequestLogs(rows) data, err := models.DecodeRequestLogs(ctx, db.db, rows)
if err != nil { if err != nil {
return nil, ct.CursorToken{}, err return nil, ct.CursorToken{}, err
} }

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -115,32 +116,32 @@ func (c ChannelWithSubscriptionDB) Model() ChannelWithSubscription {
} }
} }
func DecodeChannel(r *sqlx.Rows) (Channel, error) { func DecodeChannel(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (Channel, error) {
data, err := sq.ScanSingle[ChannelDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[ChannelDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return Channel{}, err return Channel{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeChannels(r *sqlx.Rows) ([]Channel, error) { func DecodeChannels(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]Channel, error) {
data, err := sq.ScanAll[ChannelDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[ChannelDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return langext.ArrMap(data, func(v ChannelDB) Channel { return v.Model() }), nil return langext.ArrMap(data, func(v ChannelDB) Channel { return v.Model() }), nil
} }
func DecodeChannelWithSubscription(r *sqlx.Rows) (ChannelWithSubscription, error) { func DecodeChannelWithSubscription(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (ChannelWithSubscription, error) {
data, err := sq.ScanSingle[ChannelWithSubscriptionDB](r, sq.SModeExtended, sq.Safe, true) data, err := sq.ScanSingle[ChannelWithSubscriptionDB](ctx, q, r, sq.SModeExtended, sq.Safe, true)
if err != nil { if err != nil {
return ChannelWithSubscription{}, err return ChannelWithSubscription{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeChannelsWithSubscription(r *sqlx.Rows) ([]ChannelWithSubscription, error) { func DecodeChannelsWithSubscription(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]ChannelWithSubscription, error) {
data, err := sq.ScanAll[ChannelWithSubscriptionDB](r, sq.SModeExtended, sq.Safe, true) data, err := sq.ScanAll[ChannelWithSubscriptionDB](ctx, q, r, sq.SModeExtended, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -71,16 +72,16 @@ func (c ClientDB) Model() Client {
} }
} }
func DecodeClient(r *sqlx.Rows) (Client, error) { func DecodeClient(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (Client, error) {
data, err := sq.ScanSingle[ClientDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[ClientDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return Client{}, err return Client{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeClients(r *sqlx.Rows) ([]Client, error) { func DecodeClients(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]Client, error) {
data, err := sq.ScanAll[ClientDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[ClientDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -88,16 +89,16 @@ func (d DeliveryDB) Model() Delivery {
} }
} }
func DecodeDelivery(r *sqlx.Rows) (Delivery, error) { func DecodeDelivery(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (Delivery, error) {
data, err := sq.ScanSingle[DeliveryDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[DeliveryDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return Delivery{}, err return Delivery{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeDeliveries(r *sqlx.Rows) ([]Delivery, error) { func DecodeDeliveries(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]Delivery, error) {
data, err := sq.ScanAll[DeliveryDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[DeliveryDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,7 +5,7 @@ package models
import "gogs.mikescher.com/BlackForestBytes/goext/langext" import "gogs.mikescher.com/BlackForestBytes/goext/langext"
import "gogs.mikescher.com/BlackForestBytes/goext/enums" import "gogs.mikescher.com/BlackForestBytes/goext/enums"
const ChecksumEnumGenerator = "69a99f8c01a15baad2fc9b99c516a700e02ce4dbcae452699e6d43cc23bc01bc" // GoExtVersion: 0.0.463 const ChecksumEnumGenerator = "20ad4720103f17781ed6aaa102b503abb182ac08c077b42d4f56557ef38f28eb" // GoExtVersion: 0.0.463
// ================================ ClientType ================================ // ================================ ClientType ================================
// //

View File

@ -15,7 +15,7 @@ import "reflect"
import "regexp" import "regexp"
import "strings" import "strings"
const ChecksumCharsetIDGenerator = "69a99f8c01a15baad2fc9b99c516a700e02ce4dbcae452699e6d43cc23bc01bc" // GoExtVersion: 0.0.463 const ChecksumCharsetIDGenerator = "20ad4720103f17781ed6aaa102b503abb182ac08c077b42d4f56557ef38f28eb" // GoExtVersion: 0.0.463
const idlen = 24 const idlen = 24

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -149,16 +150,16 @@ func (k KeyTokenDB) Model() KeyToken {
} }
} }
func DecodeKeyToken(r *sqlx.Rows) (KeyToken, error) { func DecodeKeyToken(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (KeyToken, error) {
data, err := sq.ScanSingle[KeyTokenDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[KeyTokenDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return KeyToken{}, err return KeyToken{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeKeyTokens(r *sqlx.Rows) ([]KeyToken, error) { func DecodeKeyTokens(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]KeyToken, error) {
data, err := sq.ScanAll[KeyTokenDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[KeyTokenDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -145,16 +146,16 @@ func (m MessageDB) Model() Message {
} }
} }
func DecodeMessage(r *sqlx.Rows) (Message, error) { func DecodeMessage(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (Message, error) {
data, err := sq.ScanSingle[MessageDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[MessageDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return Message{}, err return Message{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeMessages(r *sqlx.Rows) ([]Message, error) { func DecodeMessages(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]Message, error) {
data, err := sq.ScanAll[MessageDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[MessageDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -170,16 +171,16 @@ func (c RequestLogDB) Model() RequestLog {
} }
} }
func DecodeRequestLog(r *sqlx.Rows) (RequestLog, error) { func DecodeRequestLog(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (RequestLog, error) {
data, err := sq.ScanSingle[RequestLogDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[RequestLogDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return RequestLog{}, err return RequestLog{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeRequestLogs(r *sqlx.Rows) ([]RequestLog, error) { func DecodeRequestLogs(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]RequestLog, error) {
data, err := sq.ScanAll[RequestLogDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[RequestLogDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,7 @@
package models package models
import ( import (
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -68,16 +69,16 @@ func (s SubscriptionDB) Model() Subscription {
} }
} }
func DecodeSubscription(r *sqlx.Rows) (Subscription, error) { func DecodeSubscription(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (Subscription, error) {
data, err := sq.ScanSingle[SubscriptionDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[SubscriptionDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return Subscription{}, err return Subscription{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeSubscriptions(r *sqlx.Rows) ([]Subscription, error) { func DecodeSubscriptions(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]Subscription, error) {
data, err := sq.ScanAll[SubscriptionDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[SubscriptionDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,6 +2,7 @@ package models
import ( import (
scn "blackforestbytes.com/simplecloudnotifier" scn "blackforestbytes.com/simplecloudnotifier"
"context"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
@ -171,16 +172,16 @@ func (u UserDB) Model() User {
} }
} }
func DecodeUser(r *sqlx.Rows) (User, error) { func DecodeUser(ctx context.Context, q sq.Queryable, r *sqlx.Rows) (User, error) {
data, err := sq.ScanSingle[UserDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanSingle[UserDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return User{}, err return User{}, err
} }
return data.Model(), nil return data.Model(), nil
} }
func DecodeUsers(r *sqlx.Rows) ([]User, error) { func DecodeUsers(ctx context.Context, q sq.Queryable, r *sqlx.Rows) ([]User, error) {
data, err := sq.ScanAll[UserDB](r, sq.SModeFast, sq.Safe, true) data, err := sq.ScanAll[UserDB](ctx, q, r, sq.SModeFast, sq.Safe, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,63 +19,39 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "integer",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "query" "in": "query"
}, },
{
"type": "string",
"name": "user_key",
"in": "query"
},
{ {
"description": " ", "description": " ",
"name": "post_body", "name": "post_body",
@ -86,62 +62,38 @@
}, },
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "formData"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "integer",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "formData" "in": "formData"
},
{
"type": "string",
"name": "user_key",
"in": "formData"
} }
], ],
"responses": { "responses": {
@ -2557,63 +2509,39 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "integer",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "query" "in": "query"
}, },
{
"type": "string",
"name": "user_key",
"in": "query"
},
{ {
"description": " ", "description": " ",
"name": "post_body", "name": "post_body",
@ -2624,62 +2552,38 @@
}, },
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "formData"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "integer",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "formData" "in": "formData"
},
{
"type": "string",
"name": "user_key",
"in": "formData"
} }
], ],
"responses": { "responses": {
@ -2727,121 +2631,73 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "integer",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "test", "name": "user_key",
"name": "channel", "in": "query"
"in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "integer",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "formData" "in": "formData"
},
{
"type": "string",
"name": "user_key",
"in": "formData"
} }
], ],
"responses": { "responses": {
@ -3331,46 +3187,26 @@
"handler.SendMessage.combined": { "handler.SendMessage.combined": {
"type": "object", "type": "object",
"properties": { "properties": {
"channel": {
"type": "string",
"example": "test"
},
"content": { "content": {
"type": "string", "type": "string"
"example": "This is a message"
},
"key": {
"type": "string",
"example": "P3TNH8mvv14fm"
}, },
"msg_id": { "msg_id": {
"type": "string", "type": "string"
"example": "db8b0e6a-a08c-4646"
}, },
"priority": { "priority": {
"type": "integer", "type": "integer"
"enum": [
0,
1,
2
],
"example": 1
},
"sender_name": {
"type": "string",
"example": "example-server"
}, },
"timestamp": { "timestamp": {
"type": "number", "type": "number"
"example": 1669824037
}, },
"title": { "title": {
"type": "string", "type": "string"
"example": "Hello World"
}, },
"user_id": { "user_id": {
"type": "string", "type": "integer"
"example": "7725" },
"user_key": {
"type": "string"
} }
} }
}, },
@ -3399,7 +3235,7 @@
"type": "integer" "type": "integer"
}, },
"scn_msg_id": { "scn_msg_id": {
"type": "string" "type": "integer"
}, },
"success": { "success": {
"type": "boolean" "type": "boolean"

View File

@ -323,36 +323,19 @@ definitions:
type: object type: object
handler.SendMessage.combined: handler.SendMessage.combined:
properties: properties:
channel:
example: test
type: string
content: content:
example: This is a message
type: string
key:
example: P3TNH8mvv14fm
type: string type: string
msg_id: msg_id:
example: db8b0e6a-a08c-4646
type: string type: string
priority: priority:
enum:
- 0
- 1
- 2
example: 1
type: integer type: integer
sender_name:
example: example-server
type: string
timestamp: timestamp:
example: 1669824037
type: number type: number
title: title:
example: Hello World
type: string type: string
user_id: user_id:
example: "7725" type: integer
user_key:
type: string type: string
type: object type: object
handler.SendMessage.response: handler.SendMessage.response:
@ -372,7 +355,7 @@ definitions:
quota_max: quota_max:
type: integer type: integer
scn_msg_id: scn_msg_id:
type: string type: integer
success: success:
type: boolean type: boolean
suppress_send: suppress_send:
@ -734,90 +717,52 @@ paths:
description: All parameter can be set via query-parameter or the json body. description: All parameter can be set via query-parameter or the json body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- example: test - in: query
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- example: P3TNH8mvv14fm - in: query
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- enum: - in: query
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- example: example-server - in: query
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- example: Hello World - in: query
in: query
name: title name: title
type: string type: string
- example: "7725" - in: query
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- description: ' ' - description: ' '
in: body in: body
name: post_body name: post_body
schema: schema:
$ref: '#/definitions/handler.SendMessage.combined' $ref: '#/definitions/handler.SendMessage.combined'
- example: test - in: formData
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- example: P3TNH8mvv14fm - in: formData
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- enum: - in: formData
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- example: example-server - in: formData
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- example: Hello World - in: formData
in: formData
name: title name: title
type: string type: string
- example: "7725" - in: formData
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":
@ -2475,90 +2420,52 @@ paths:
description: All parameter can be set via query-parameter or the json body. description: All parameter can be set via query-parameter or the json body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- example: test - in: query
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- example: P3TNH8mvv14fm - in: query
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- enum: - in: query
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- example: example-server - in: query
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- example: Hello World - in: query
in: query
name: title name: title
type: string type: string
- example: "7725" - in: query
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- description: ' ' - description: ' '
in: body in: body
name: post_body name: post_body
schema: schema:
$ref: '#/definitions/handler.SendMessage.combined' $ref: '#/definitions/handler.SendMessage.combined'
- example: test - in: formData
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- example: P3TNH8mvv14fm - in: formData
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- enum: - in: formData
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- example: example-server - in: formData
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- example: Hello World - in: formData
in: formData
name: title name: title
type: string type: string
- example: "7725" - in: formData
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":
@ -2591,85 +2498,47 @@ paths:
description: All parameter can be set via query-parameter or form-data body. description: All parameter can be set via query-parameter or form-data body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- example: test - in: query
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- example: P3TNH8mvv14fm - in: query
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- enum: - in: query
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- example: example-server - in: query
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- example: Hello World - in: query
in: query
name: title name: title
type: string type: string
- example: "7725" - in: query
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- example: test - in: formData
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- example: P3TNH8mvv14fm - in: formData
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- enum: - in: formData
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- example: example-server - in: formData
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- example: Hello World - in: formData
in: formData
name: title name: title
type: string type: string
- example: "7725" - in: formData
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":

View File

@ -310,7 +310,7 @@ func TestPrimaryDB_Migrate_from_3(t *testing.T) {
xdb, err := sqlx.Open("sqlite3", url) xdb, err := sqlx.Open("sqlite3", url)
tt.TestFailIfErr(t, err) tt.TestFailIfErr(t, err)
qqdb := sq.NewDB(xdb) qqdb := sq.NewDB(xdb, sq.DBOptions{})
schemavers := 3 schemavers := 3

View File

@ -0,0 +1,15 @@
package test
import (
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"os"
"testing"
)
func TestMain(m *testing.M) {
if !exerr.Initialized() {
exerr.Init(exerr.ErrorPackageConfigInit{ZeroLogErrTraces: langext.PFalse, ZeroLogAllTraces: langext.PFalse})
}
os.Exit(m.Run())
}