finish setup data insertion, add world insertion
This commit is contained in:
@@ -2,9 +2,12 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type SetupLanguage struct {
|
||||
@@ -33,11 +36,10 @@ func (l *SetupLanguage) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
|
||||
return err
|
||||
}
|
||||
|
||||
syncDB := NewSyncDB()
|
||||
defer close(syncDB.errChan)
|
||||
InsertSliceParallel(syncDB, tx, l.Modules, &InsertId[string]{id: l.ID})
|
||||
group, _ := errgroup.WithContext(context.Background())
|
||||
InsertSliceParallel(group, tx, l.Modules, InsertId[string]{id: l.ID})
|
||||
|
||||
return nil
|
||||
return group.Wait()
|
||||
}
|
||||
|
||||
func (l *SetupLanguage) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[uint]) error {
|
||||
@@ -52,10 +54,13 @@ func (l *SetupLanguage) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *Insert
|
||||
return err
|
||||
}
|
||||
|
||||
syncDB := NewSyncDB()
|
||||
defer close(syncDB.errChan)
|
||||
InsertSliceParallel(syncDB, tx, l.Modules, &InsertId[string]{id: l.ID})
|
||||
group, _ := errgroup.WithContext(context.Background())
|
||||
InsertSliceParallel(group, tx, l.Modules, InsertId[string]{id: l.ID})
|
||||
|
||||
err = group.Wait()
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -125,7 +130,7 @@ func (l *Language) Insert(tx *sqlx.Tx, data *InsertId[string]) error {
|
||||
|
||||
args := []any{data.id, l.Lang, l.Name, l.Path}
|
||||
|
||||
err := tx.QueryRow(data.query, args...).Scan(&l.ID)
|
||||
err := tx.QueryRowx(data.query, args...).Scan(&l.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -140,7 +145,7 @@ func (l *Language) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[st
|
||||
|
||||
args := []any{data.id, l.Lang, l.Name, l.Path}
|
||||
|
||||
err := tx.QueryRowContext(ctx, data.query, args...).Scan(&l.ID)
|
||||
err := tx.QueryRowxContext(ctx, data.query, args...).Scan(&l.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user