Be selective

This commit is contained in:
Daniel Ponte 2025-02-22 15:53:45 -05:00
parent 78bd29b316
commit cbe4bab78f
2 changed files with 102 additions and 72 deletions

View file

@ -28,14 +28,14 @@ VALUES
`
type AddAlertParams struct {
Time pgtype.Timestamptz `json:"time,omitempty"`
TGID int `json:"tgid,omitempty"`
SystemID int `json:"systemId,omitempty"`
Weight *float32 `json:"weight,omitempty"`
Score *float32 `json:"score,omitempty"`
OrigScore *float32 `json:"origScore,omitempty"`
Notified bool `json:"notified,omitempty"`
Metadata []byte `json:"metadata,omitempty"`
Time pgtype.Timestamptz `json:"time"`
TGID int `json:"tgid"`
SystemID int `json:"systemId"`
Weight *float32 `json:"weight"`
Score *float32 `json:"score"`
OrigScore *float32 `json:"origScore"`
Notified bool `json:"notified"`
Metadata []byte `json:"metadata"`
}
func (q *Queries) AddAlert(ctx context.Context, arg AddAlertParams) error {
@ -95,24 +95,24 @@ $18
`
type AddCallParams struct {
ID uuid.UUID `json:"id,omitempty"`
Submitter *int32 `json:"submitter,omitempty"`
System int `json:"system,omitempty"`
Talkgroup int `json:"talkgroup,omitempty"`
CallDate pgtype.Timestamptz `json:"callDate,omitempty"`
AudioName *string `json:"audioName,omitempty"`
AudioBlob []byte `json:"audioBlob,omitempty"`
AudioType *string `json:"audioType,omitempty"`
AudioUrl *string `json:"audioUrl,omitempty"`
Duration *int32 `json:"duration,omitempty"`
Frequency int `json:"frequency,omitempty"`
Frequencies []int `json:"frequencies,omitempty"`
Patches []int `json:"patches,omitempty"`
ID uuid.UUID `json:"id"`
Submitter *int32 `json:"submitter"`
System int `json:"system"`
Talkgroup int `json:"talkgroup"`
CallDate pgtype.Timestamptz `json:"callDate"`
AudioName *string `json:"audioName"`
AudioBlob []byte `json:"audioBlob"`
AudioType *string `json:"audioType"`
AudioUrl *string `json:"audioUrl"`
Duration *int32 `json:"duration"`
Frequency int `json:"frequency"`
Frequencies []int `json:"frequencies"`
Patches []int `json:"patches"`
TalkerAlias *string `json:"talkerAlias,omitempty"`
TGLabel *string `json:"tgLabel,omitempty"`
TGAlphaTag *string `json:"tgAlphaTag,omitempty"`
TGGroup *string `json:"tgGroup,omitempty"`
Source int `json:"source,omitempty"`
TGLabel *string `json:"tgLabel"`
TGAlphaTag *string `json:"tgAlphaTag"`
TGGroup *string `json:"tgGroup"`
Source int `json:"source"`
}
func (q *Queries) AddCall(ctx context.Context, arg AddCallParams) error {
@ -193,24 +193,24 @@ WHERE id = $1
`
type GetCallRow struct {
ID uuid.UUID `json:"id,omitempty"`
Submitter *int32 `json:"submitter,omitempty"`
System int `json:"system,omitempty"`
Talkgroup int `json:"talkgroup,omitempty"`
CallDate pgtype.Timestamptz `json:"callDate,omitempty"`
AudioName *string `json:"audioName,omitempty"`
AudioType *string `json:"audioType,omitempty"`
AudioUrl *string `json:"audioUrl,omitempty"`
Duration *int32 `json:"duration,omitempty"`
Frequency int `json:"frequency,omitempty"`
Frequencies []int `json:"frequencies,omitempty"`
Patches []int `json:"patches,omitempty"`
ID uuid.UUID `json:"id"`
Submitter *int32 `json:"submitter"`
System int `json:"system"`
Talkgroup int `json:"talkgroup"`
CallDate pgtype.Timestamptz `json:"callDate"`
AudioName *string `json:"audioName"`
AudioType *string `json:"audioType"`
AudioUrl *string `json:"audioUrl"`
Duration *int32 `json:"duration"`
Frequency int `json:"frequency"`
Frequencies []int `json:"frequencies"`
Patches []int `json:"patches"`
TalkerAlias *string `json:"talkerAlias,omitempty"`
TGLabel *string `json:"tgLabel,omitempty"`
TGAlphaTag *string `json:"tgAlphaTag,omitempty"`
TGGroup *string `json:"tgGroup,omitempty"`
Source int `json:"source,omitempty"`
Transcript *string `json:"transcript,omitempty"`
TGLabel *string `json:"tgLabel"`
TGAlphaTag *string `json:"tgAlphaTag"`
TGGroup *string `json:"tgGroup"`
Source int `json:"source"`
Transcript *string `json:"transcript"`
}
func (q *Queries) GetCall(ctx context.Context, id uuid.UUID) (GetCallRow, error) {
@ -258,10 +258,10 @@ WHERE sc.id = $1
`
type GetCallAudioByIDRow struct {
CallDate pgtype.Timestamptz `json:"callDate,omitempty"`
AudioName *string `json:"audioName,omitempty"`
AudioType *string `json:"audioType,omitempty"`
AudioBlob []byte `json:"audioBlob,omitempty"`
CallDate pgtype.Timestamptz `json:"callDate"`
AudioName *string `json:"audioName"`
AudioType *string `json:"audioType"`
AudioBlob []byte `json:"audioBlob"`
}
func (q *Queries) GetCallAudioByID(ctx context.Context, id uuid.UUID) (GetCallAudioByIDRow, error) {
@ -323,12 +323,12 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN
`
type ListCallsCountParams struct {
Start pgtype.Timestamptz `json:"start,omitempty"`
End pgtype.Timestamptz `json:"end,omitempty"`
TagsAny []string `json:"tagsAny,omitempty"`
TagsNot []string `json:"tagsNot,omitempty"`
TGFilter *string `json:"tgFilter,omitempty"`
LongerThan pgtype.Numeric `json:"longerThan,omitempty"`
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
LongerThan pgtype.Numeric `json:"longerThan"`
}
func (q *Queries) ListCallsCount(ctx context.Context, arg ListCallsCountParams) (int64, error) {
@ -384,23 +384,23 @@ FETCH NEXT $9 ROWS ONLY
`
type ListCallsPParams struct {
Start pgtype.Timestamptz `json:"start,omitempty"`
End pgtype.Timestamptz `json:"end,omitempty"`
TagsAny []string `json:"tagsAny,omitempty"`
TagsNot []string `json:"tagsNot,omitempty"`
TGFilter *string `json:"tgFilter,omitempty"`
LongerThan pgtype.Numeric `json:"longerThan,omitempty"`
Direction string `json:"direction,omitempty"`
Offset int32 `json:"offset,omitempty"`
PerPage int32 `json:"perPage,omitempty"`
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
LongerThan pgtype.Numeric `json:"longerThan"`
Direction string `json:"direction"`
Offset int32 `json:"offset"`
PerPage int32 `json:"perPage"`
}
type ListCallsPRow struct {
ID uuid.UUID `json:"id,omitempty"`
CallDate pgtype.Timestamptz `json:"callDate,omitempty"`
Duration *int32 `json:"duration,omitempty"`
SystemID int `json:"systemId,omitempty"`
TGID int `json:"tgid,omitempty"`
ID uuid.UUID `json:"id"`
CallDate pgtype.Timestamptz `json:"callDate"`
Duration *int32 `json:"duration"`
SystemID int `json:"systemId"`
TGID int `json:"tgid"`
TalkerAlias *string `json:"talkerAlias,omitempty"`
Incidents int64 `json:"incidents,omitempty"`
}

View file

@ -12,19 +12,46 @@ import (
"strings"
)
var filePaths = []string{
"./pkg/database/models.go",
"./pkg/database/calls.sql.go",
type FileMap map[string]FieldDecider
var filePaths = FileMap{
"./pkg/database/models.go": AllFields{},
"./pkg/database/calls.sql.go": FieldMap{
"TalkerAlias": true,
"Incidents": true,
},
}
type FieldDecider interface {
Check(fields []*ast.Ident) bool
}
type FieldMap map[string]bool
func (fm FieldMap) Check(f []*ast.Ident) bool {
for _, v := range f {
if v != nil && fm[v.Name] {
return true
}
}
return false
}
type AllFields struct{}
func (AllFields) Check(_ []*ast.Ident) bool {
return true
}
func main() {
// Parse the source code
for _, v := range filePaths {
process(v)
for k, v := range filePaths {
process(k, v)
}
}
func process(filePath string) {
func process(filePath string, fd FieldDecider) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, filePath, nil, parser.ParseComments)
if err != nil {
@ -36,6 +63,9 @@ func process(filePath string) {
switch x := n.(type) {
case *ast.StructType:
for _, field := range x.Fields.List {
if !fd.Check(field.Names) {
continue
}
if field.Tag == nil {
continue
}