-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* gorm * types.Mod * wip * log entity * chatlog * metric * oauth entity * mesecons entity * cleanup * go mod tidy --------- Co-authored-by: BuckarooBanzay <[email protected]>
- Loading branch information
1 parent
15b0a63
commit 7f53146
Showing
36 changed files
with
440 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"mtui/types" | ||
|
||
"github.com/minetest-go/dbutil" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/clause" | ||
) | ||
|
||
type ConfigRepository struct { | ||
dbu *dbutil.DBUtil[*types.ConfigEntry] | ||
g *gorm.DB | ||
} | ||
|
||
func (r *ConfigRepository) GetByKey(key types.ConfigKey) (*types.ConfigEntry, error) { | ||
c, err := r.dbu.Select("where key = %s", key) | ||
if err == sql.ErrNoRows { | ||
return nil, nil | ||
var list []*types.ConfigEntry | ||
err := r.g.Where(types.ConfigEntry{Key: key}).Limit(1).Find(&list).Error | ||
if len(list) == 0 { | ||
return nil, err | ||
} | ||
return c, err | ||
return list[0], err | ||
} | ||
|
||
func (r *ConfigRepository) Set(c *types.ConfigEntry) error { | ||
return r.dbu.InsertOrReplace(c) | ||
return r.g.Clauses(clause.OnConflict{ | ||
Columns: []clause.Column{{Name: "key"}}, | ||
UpdateAll: true, | ||
}).Create(c).Error | ||
} | ||
|
||
func (r *ConfigRepository) Delete(key string) error { | ||
return r.dbu.Delete("where key = %s", key) | ||
func (r *ConfigRepository) Delete(key types.ConfigKey) error { | ||
return r.g.Delete(types.ConfigEntry{Key: key}).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"mtui/types" | ||
|
||
"github.com/minetest-go/dbutil" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/clause" | ||
) | ||
|
||
type FeatureRepository struct { | ||
dbu *dbutil.DBUtil[*types.Feature] | ||
g *gorm.DB | ||
} | ||
|
||
func (r *FeatureRepository) Set(m *types.Feature) error { | ||
return r.dbu.InsertOrReplace(m) | ||
return r.g.Clauses(clause.OnConflict{ | ||
Columns: []clause.Column{{Name: "name"}}, | ||
UpdateAll: true, | ||
}).Create(m).Error | ||
} | ||
|
||
func (r *FeatureRepository) GetAll() ([]*types.Feature, error) { | ||
return r.dbu.SelectMulti("") | ||
var list []*types.Feature | ||
err := r.g.Find(&list).Error | ||
return list, err | ||
} | ||
|
||
func (r *FeatureRepository) GetByName(name string) (*types.Feature, error) { | ||
f, err := r.dbu.Select("where name = %s", name) | ||
if err == sql.ErrNoRows { | ||
return nil, nil | ||
} else { | ||
return f, err | ||
var list []*types.Feature | ||
err := r.g.Where(types.Feature{Name: name}).Limit(1).Find(&list).Error | ||
if len(list) == 0 { | ||
return nil, err | ||
} | ||
return list[0], err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.