add db delete queries, fix module_id
This commit is contained in:
@@ -151,6 +151,62 @@ func (m FoundryStateModel) GetWorldsCompatibility(idWorld int64) (*Compatibility
|
||||
return &compatibility, nil
|
||||
}
|
||||
|
||||
func (m FoundryStateModel) DeleteWorlds(idState int64) error {
|
||||
if idState < 1 {
|
||||
return ErrorRecordNotFound
|
||||
}
|
||||
|
||||
query := `
|
||||
DELETE FROM worlds
|
||||
WHERE state_id = $1`
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := m.DB.ExecContext(ctx, query, idState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
return ErrorRecordNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m FoundryStateModel) DeleteWorld(idWorld int64) error {
|
||||
if idWorld < 1 {
|
||||
return ErrorRecordNotFound
|
||||
}
|
||||
|
||||
query := `
|
||||
DELETE FROM worlds
|
||||
WHERE id = $1`
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := m.DB.ExecContext(ctx, query, idWorld)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
return ErrorRecordNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (worlds Worlds) GetSessionTime(worldName string) (*time.Time, error) {
|
||||
// if worldName == "" && len(worlds) != 1 {
|
||||
// return nil, ErrorSetupNotFound
|
||||
|
||||
Reference in New Issue
Block a user