所有数据库相关的操作支持事务

This commit is contained in:
刘祥超
2021-01-01 23:31:30 +08:00
parent 0cf398a436
commit f49c26cdab
146 changed files with 2845 additions and 2068 deletions

View File

@@ -35,8 +35,8 @@ func init() {
}
// 启用条目
func (this *RegionProvinceDAO) EnableRegionProvince(id int64) error {
_, err := this.Query().
func (this *RegionProvinceDAO) EnableRegionProvince(tx *dbs.Tx, id int64) error {
_, err := this.Query(tx).
Pk(id).
Set("state", RegionProvinceStateEnabled).
Update()
@@ -44,8 +44,8 @@ func (this *RegionProvinceDAO) EnableRegionProvince(id int64) error {
}
// 禁用条目
func (this *RegionProvinceDAO) DisableRegionProvince(id int64) error {
_, err := this.Query().
func (this *RegionProvinceDAO) DisableRegionProvince(tx *dbs.Tx, id int64) error {
_, err := this.Query(tx).
Pk(id).
Set("state", RegionProvinceStateDisabled).
Update()
@@ -53,8 +53,8 @@ func (this *RegionProvinceDAO) DisableRegionProvince(id int64) error {
}
// 查找启用中的条目
func (this *RegionProvinceDAO) FindEnabledRegionProvince(id int64) (*RegionProvince, error) {
result, err := this.Query().
func (this *RegionProvinceDAO) FindEnabledRegionProvince(tx *dbs.Tx, id int64) (*RegionProvince, error) {
result, err := this.Query(tx).
Pk(id).
Attr("state", RegionProvinceStateEnabled).
Find()
@@ -65,16 +65,16 @@ func (this *RegionProvinceDAO) FindEnabledRegionProvince(id int64) (*RegionProvi
}
// 根据主键查找名称
func (this *RegionProvinceDAO) FindRegionProvinceName(id int64) (string, error) {
return this.Query().
func (this *RegionProvinceDAO) FindRegionProvinceName(tx *dbs.Tx, id int64) (string, error) {
return this.Query(tx).
Pk(id).
Result("name").
FindStringCol("")
}
// 根据数据ID查找省份
func (this *RegionProvinceDAO) FindProvinceIdWithDataId(dataId string) (int64, error) {
return this.Query().
func (this *RegionProvinceDAO) FindProvinceIdWithDataId(tx *dbs.Tx, dataId string) (int64, error) {
return this.Query(tx).
Attr("dataId", dataId).
ResultPk().
FindInt64Col(0)
@@ -82,8 +82,8 @@ func (this *RegionProvinceDAO) FindProvinceIdWithDataId(dataId string) (int64, e
// 根据省份名查找省份ID
// TODO 加入缓存
func (this *RegionProvinceDAO) FindProvinceIdWithProvinceName(provinceName string) (int64, error) {
return this.Query().
func (this *RegionProvinceDAO) FindProvinceIdWithProvinceName(tx *dbs.Tx, provinceName string) (int64, error) {
return this.Query(tx).
Where("JSON_CONTAINS(codes, :provinceName)").
Param("provinceName", "\""+provinceName+"\""). // 查询的需要是个JSON字符串所以这里加双引号
ResultPk().
@@ -91,7 +91,7 @@ func (this *RegionProvinceDAO) FindProvinceIdWithProvinceName(provinceName strin
}
// 创建省份
func (this *RegionProvinceDAO) CreateProvince(countryId int64, name string, dataId string) (int64, error) {
func (this *RegionProvinceDAO) CreateProvince(tx *dbs.Tx, countryId int64, name string, dataId string) (int64, error) {
op := NewRegionProvinceOperator()
op.CountryId = countryId
op.Name = name
@@ -104,7 +104,7 @@ func (this *RegionProvinceDAO) CreateProvince(countryId int64, name string, data
return 0, err
}
op.Codes = codesJSON
err = this.Save(op)
err = this.Save(tx, op)
if err != nil {
return 0, err
}
@@ -112,8 +112,8 @@ func (this *RegionProvinceDAO) CreateProvince(countryId int64, name string, data
}
// 查找所有省份
func (this *RegionProvinceDAO) FindAllEnabledProvincesWithCountryId(countryId int64) (result []*RegionProvince, err error) {
_, err = this.Query().
func (this *RegionProvinceDAO) FindAllEnabledProvincesWithCountryId(tx *dbs.Tx, countryId int64) (result []*RegionProvince, err error) {
_, err = this.Query(tx).
State(RegionProvinceStateEnabled).
Attr("countryId", countryId).
Asc().