-
Notifications
You must be signed in to change notification settings - Fork 352
/
user_global_privacy_settings_dao.go
111 lines (93 loc) · 3.8 KB
/
user_global_privacy_settings_dao.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* WARNING! All changes made in this file will be lost!
* Created from by 'dalgen'
*
* Copyright (c) 2022-present, Teamgram Authors.
* All rights reserved.
*
* Author: teamgramio (teamgram.io@gmail.com)
*/
package mysql_dao
import (
"context"
"database/sql"
"github.com/teamgram/marmota/pkg/stores/sqlx"
"github.com/teamgram/teamgram-server/app/service/biz/user/internal/dal/dataobject"
"github.com/zeromicro/go-zero/core/logx"
)
var _ *sql.Result
type UserGlobalPrivacySettingsDAO struct {
db *sqlx.DB
}
func NewUserGlobalPrivacySettingsDAO(db *sqlx.DB) *UserGlobalPrivacySettingsDAO {
return &UserGlobalPrivacySettingsDAO{db}
}
// InsertOrUpdate
// insert into user_global_privacy_settings(user_id, archive_and_mute_new_noncontact_peers) values (:user_id, :archive_and_mute_new_noncontact_peers) on duplicate key update archive_and_mute_new_noncontact_peers = values(archive_and_mute_new_noncontact_peers)
// TODO(@benqi): sqlmap
func (dao *UserGlobalPrivacySettingsDAO) InsertOrUpdate(ctx context.Context, do *dataobject.UserGlobalPrivacySettingsDO) (lastInsertId, rowsAffected int64, err error) {
var (
query = "insert into user_global_privacy_settings(user_id, archive_and_mute_new_noncontact_peers) values (:user_id, :archive_and_mute_new_noncontact_peers) on duplicate key update archive_and_mute_new_noncontact_peers = values(archive_and_mute_new_noncontact_peers)"
r sql.Result
)
r, err = dao.db.NamedExec(ctx, query, do)
if err != nil {
logx.WithContext(ctx).Errorf("namedExec in InsertOrUpdate(%v), error: %v", do, err)
return
}
lastInsertId, err = r.LastInsertId()
if err != nil {
logx.WithContext(ctx).Errorf("lastInsertId in InsertOrUpdate(%v)_error: %v", do, err)
return
}
rowsAffected, err = r.RowsAffected()
if err != nil {
logx.WithContext(ctx).Errorf("rowsAffected in InsertOrUpdate(%v)_error: %v", do, err)
}
return
}
// InsertOrUpdateTx
// insert into user_global_privacy_settings(user_id, archive_and_mute_new_noncontact_peers) values (:user_id, :archive_and_mute_new_noncontact_peers) on duplicate key update archive_and_mute_new_noncontact_peers = values(archive_and_mute_new_noncontact_peers)
// TODO(@benqi): sqlmap
func (dao *UserGlobalPrivacySettingsDAO) InsertOrUpdateTx(tx *sqlx.Tx, do *dataobject.UserGlobalPrivacySettingsDO) (lastInsertId, rowsAffected int64, err error) {
var (
query = "insert into user_global_privacy_settings(user_id, archive_and_mute_new_noncontact_peers) values (:user_id, :archive_and_mute_new_noncontact_peers) on duplicate key update archive_and_mute_new_noncontact_peers = values(archive_and_mute_new_noncontact_peers)"
r sql.Result
)
r, err = tx.NamedExec(query, do)
if err != nil {
logx.WithContext(tx.Context()).Errorf("namedExec in InsertOrUpdate(%v), error: %v", do, err)
return
}
lastInsertId, err = r.LastInsertId()
if err != nil {
logx.WithContext(tx.Context()).Errorf("lastInsertId in InsertOrUpdate(%v)_error: %v", do, err)
return
}
rowsAffected, err = r.RowsAffected()
if err != nil {
logx.WithContext(tx.Context()).Errorf("rowsAffected in InsertOrUpdate(%v)_error: %v", do, err)
}
return
}
// Select
// select id, user_id, archive_and_mute_new_noncontact_peers from user_global_privacy_settings where user_id = :user_id
// TODO(@benqi): sqlmap
func (dao *UserGlobalPrivacySettingsDAO) Select(ctx context.Context, user_id int64) (rValue *dataobject.UserGlobalPrivacySettingsDO, err error) {
var (
query = "select id, user_id, archive_and_mute_new_noncontact_peers from user_global_privacy_settings where user_id = ?"
do = &dataobject.UserGlobalPrivacySettingsDO{}
)
err = dao.db.QueryRowPartial(ctx, do, query, user_id)
if err != nil {
if err != sqlx.ErrNotFound {
logx.WithContext(ctx).Errorf("queryx in Select(_), error: %v", err)
return
} else {
err = nil
}
} else {
rValue = do
}
return
}