/
db_detect_word.go
46 lines (40 loc) · 1.75 KB
/
db_detect_word.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
package main
import (
"context"
"github.com/ca-risken/osint/pkg/model"
"github.com/vikyd/zero"
)
func (r *osintRepository) ListOsintDetectWord(ctx context.Context, projectID, relOsintDataSourceID uint32) (*[]model.OsintDetectWord, error) {
query := `select * from osint_detect_word where project_id = ?`
var params []interface{}
params = append(params, projectID)
if !zero.IsZeroVal(relOsintDataSourceID) {
query += " and rel_osint_data_source_id = ?"
params = append(params, relOsintDataSourceID)
}
var data []model.OsintDetectWord
if err := r.SlaveDB.WithContext(ctx).Raw(query, params...).Scan(&data).Error; err != nil {
return nil, err
}
return &data, nil
}
func (r *osintRepository) GetOsintDetectWord(ctx context.Context, projectID uint32, osintDetectWordID uint32) (*model.OsintDetectWord, error) {
var data model.OsintDetectWord
if err := r.SlaveDB.WithContext(ctx).Where("project_id = ? AND osint_detect_word_id = ?", projectID, osintDetectWordID).First(&data).Error; err != nil {
return nil, err
}
return &data, nil
}
func (r *osintRepository) UpsertOsintDetectWord(ctx context.Context, data *model.OsintDetectWord) (*model.OsintDetectWord, error) {
var savedData model.OsintDetectWord
if err := r.MasterDB.WithContext(ctx).Where("project_id = ? AND osint_detect_word_id = ?", data.ProjectID, data.OsintDetectWordID).Assign(data).FirstOrCreate(&savedData).Error; err != nil {
return nil, err
}
return &savedData, nil
}
func (r *osintRepository) DeleteOsintDetectWord(ctx context.Context, projectID uint32, osintDetectWordID uint32) error {
if err := r.MasterDB.WithContext(ctx).Where("project_id = ? AND osint_detect_word_id = ?", projectID, osintDetectWordID).Delete(&model.OsintDetectWord{}).Error; err != nil {
return err
}
return nil
}