refactor: Update ARR body parsing logic

This commit is contained in:
windyboy
2024-07-23 12:34:14 +08:00
parent 3b9b64ec9e
commit 12a9da1ca1
6 changed files with 38 additions and 124 deletions
+18 -26
View File
@@ -4,6 +4,7 @@ package repository
import ( import (
"context" "context"
"encoding/json"
"time" "time"
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
@@ -12,29 +13,28 @@ import (
// input type for inserting data into table "aviation.telegrams" // input type for inserting data into table "aviation.telegrams"
type Aviation_telegrams_insert_input struct { type Aviation_telegrams_insert_input struct {
Body_and_footer string `json:"body_and_footer"` Body_and_footer string `json:"body_and_footer"`
Body_data string `json:"body_data"` Body_data json.RawMessage `json:"body_data"`
Category string `json:"category"` Category string `json:"category"`
Date_time string `json:"date_time"` Date_time string `json:"date_time"`
Dispatched_at time.Time `json:"dispatched_at"` Dispatched_at time.Time `json:"dispatched_at"`
Id int `json:"id"` Message_id string `json:"message_id"`
Message_id string `json:"message_id"` Need_dispatch bool `json:"need_dispatch"`
Need_dispatch bool `json:"need_dispatch"` Originator string `json:"originator"`
Originator string `json:"originator"` Originator_date_time string `json:"originator_date_time"`
Originator_date_time string `json:"originator_date_time"` Parsed_at time.Time `json:"parsed_at"`
Parsed_at time.Time `json:"parsed_at"` Primary_address string `json:"primary_address"`
Primary_address string `json:"primary_address"` Priority_indicator string `json:"priority_indicator"`
Priority_indicator string `json:"priority_indicator"` Received_at time.Time `json:"received_at"`
Received_at time.Time `json:"received_at"` Secondary_addresses json.RawMessage `json:"secondary_addresses"`
Secondary_addresses string `json:"secondary_addresses"` Uuid uuid.UUID `json:"uuid"`
Uuid uuid.UUID `json:"uuid"`
} }
// GetBody_and_footer returns Aviation_telegrams_insert_input.Body_and_footer, and is useful for accessing the field via an interface. // GetBody_and_footer returns Aviation_telegrams_insert_input.Body_and_footer, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetBody_and_footer() string { return v.Body_and_footer } func (v *Aviation_telegrams_insert_input) GetBody_and_footer() string { return v.Body_and_footer }
// GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface. // GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetBody_data() string { return v.Body_data } func (v *Aviation_telegrams_insert_input) GetBody_data() json.RawMessage { return v.Body_data }
// GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface. // GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category } func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category }
@@ -45,9 +45,6 @@ func (v *Aviation_telegrams_insert_input) GetDate_time() string { return v.Date_
// GetDispatched_at returns Aviation_telegrams_insert_input.Dispatched_at, and is useful for accessing the field via an interface. // GetDispatched_at returns Aviation_telegrams_insert_input.Dispatched_at, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetDispatched_at() time.Time { return v.Dispatched_at } func (v *Aviation_telegrams_insert_input) GetDispatched_at() time.Time { return v.Dispatched_at }
// GetId returns Aviation_telegrams_insert_input.Id, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetId() int { return v.Id }
// GetMessage_id returns Aviation_telegrams_insert_input.Message_id, and is useful for accessing the field via an interface. // GetMessage_id returns Aviation_telegrams_insert_input.Message_id, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetMessage_id() string { return v.Message_id } func (v *Aviation_telegrams_insert_input) GetMessage_id() string { return v.Message_id }
@@ -75,7 +72,7 @@ func (v *Aviation_telegrams_insert_input) GetPriority_indicator() string { retur
func (v *Aviation_telegrams_insert_input) GetReceived_at() time.Time { return v.Received_at } func (v *Aviation_telegrams_insert_input) GetReceived_at() time.Time { return v.Received_at }
// GetSecondary_addresses returns Aviation_telegrams_insert_input.Secondary_addresses, and is useful for accessing the field via an interface. // GetSecondary_addresses returns Aviation_telegrams_insert_input.Secondary_addresses, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() string { func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() json.RawMessage {
return v.Secondary_addresses return v.Secondary_addresses
} }
@@ -95,14 +92,10 @@ func (v *__newMessageInput) GetObject() Aviation_telegrams_insert_input { return
// //
// columns and relationships of "aviation.telegrams" // columns and relationships of "aviation.telegrams"
type newMessageInsert_aviation_telegrams_oneAviation_telegrams struct { type newMessageInsert_aviation_telegrams_oneAviation_telegrams struct {
Id int `json:"id"`
Message_id string `json:"message_id"` Message_id string `json:"message_id"`
Uuid uuid.UUID `json:"uuid"` Uuid uuid.UUID `json:"uuid"`
} }
// GetId returns newMessageInsert_aviation_telegrams_oneAviation_telegrams.Id, and is useful for accessing the field via an interface.
func (v *newMessageInsert_aviation_telegrams_oneAviation_telegrams) GetId() int { return v.Id }
// GetMessage_id returns newMessageInsert_aviation_telegrams_oneAviation_telegrams.Message_id, and is useful for accessing the field via an interface. // GetMessage_id returns newMessageInsert_aviation_telegrams_oneAviation_telegrams.Message_id, and is useful for accessing the field via an interface.
func (v *newMessageInsert_aviation_telegrams_oneAviation_telegrams) GetMessage_id() string { func (v *newMessageInsert_aviation_telegrams_oneAviation_telegrams) GetMessage_id() string {
return v.Message_id return v.Message_id
@@ -128,7 +121,6 @@ func (v *newMessageResponse) GetInsert_aviation_telegrams_one() newMessageInsert
const newMessage_Operation = ` const newMessage_Operation = `
mutation newMessage ($object: aviation_telegrams_insert_input!) { mutation newMessage ($object: aviation_telegrams_insert_input!) {
insert_aviation_telegrams_one(object: $object) { insert_aviation_telegrams_one(object: $object) {
id
message_id message_id
uuid uuid
} }
-1
View File
@@ -1,6 +1,5 @@
mutation newMessage($object: aviation_telegrams_insert_input!) { mutation newMessage($object: aviation_telegrams_insert_input!) {
insert_aviation_telegrams_one(object: $object) { insert_aviation_telegrams_one(object: $object) {
id
message_id message_id
uuid uuid
} }
+1 -1
View File
@@ -6,7 +6,7 @@ operations:
generated: generated.go generated: generated.go
bindings: bindings:
jsonb: jsonb:
type: string type: encoding/json.RawMessage
timestamp: timestamp:
type: time.Time type: time.Time
uuid: uuid:
+11 -11
View File
@@ -10,11 +10,11 @@
"TotalSpecs": 1, "TotalSpecs": 1,
"SpecsThatWillRun": 1 "SpecsThatWillRun": 1
}, },
"StartTime": "2024-07-23T12:01:15.75278901+08:00", "StartTime": "2024-07-23T12:33:42.47682339+08:00",
"EndTime": "2024-07-23T12:01:15.764655302+08:00", "EndTime": "2024-07-23T12:33:42.480755442+08:00",
"RunTime": 11866337, "RunTime": 3932052,
"SuiteConfig": { "SuiteConfig": {
"RandomSeed": 1721707275, "RandomSeed": 1721709222,
"RandomizeAllSpecs": false, "RandomizeAllSpecs": false,
"FocusStrings": [ "FocusStrings": [
"Repositories Hasura Repository should mutate a parsed message" "Repositories Hasura Repository should mutate a parsed message"
@@ -31,7 +31,7 @@
"DryRun": false, "DryRun": false,
"PollProgressAfter": 0, "PollProgressAfter": 0,
"PollProgressInterval": 0, "PollProgressInterval": 0,
"Timeout": 3599595734975, "Timeout": 3599595857926,
"EmitSpecProgress": false, "EmitSpecProgress": false,
"OutputInterceptorMode": "", "OutputInterceptorMode": "",
"SourceRoots": null, "SourceRoots": null,
@@ -68,9 +68,9 @@
"LeafNodeLabels": [], "LeafNodeLabels": [],
"LeafNodeText": "should mutate a parsed message", "LeafNodeText": "should mutate a parsed message",
"State": "passed", "State": "passed",
"StartTime": "2024-07-23T12:01:15.752849553+08:00", "StartTime": "2024-07-23T12:33:42.476903287+08:00",
"EndTime": "2024-07-23T12:01:15.764585492+08:00", "EndTime": "2024-07-23T12:33:42.480729619+08:00",
"RunTime": 11735991, "RunTime": 3826334,
"ParallelProcess": 1, "ParallelProcess": 1,
"NumAttempts": 1, "NumAttempts": 1,
"MaxFlakeAttempts": 0, "MaxFlakeAttempts": 0,
@@ -84,7 +84,7 @@
}, },
"TimelineLocation": { "TimelineLocation": {
"Order": 1, "Order": 1,
"Time": "2024-07-23T12:01:15.752859429+08:00" "Time": "2024-07-23T12:33:42.476916857+08:00"
}, },
"Message": "should mutate a parsed message", "Message": "should mutate a parsed message",
"NodeType": "It" "NodeType": "It"
@@ -97,10 +97,10 @@
}, },
"TimelineLocation": { "TimelineLocation": {
"Order": 3, "Order": 3,
"Time": "2024-07-23T12:01:15.764576564+08:00" "Time": "2024-07-23T12:33:42.480726236+08:00"
}, },
"Message": "should mutate a parsed message", "Message": "should mutate a parsed message",
"Duration": 11717183, "Duration": 3809380,
"NodeType": "It" "NodeType": "It"
} }
] ]
+2 -1
View File
@@ -33,11 +33,12 @@ func (hr *HasuraRepository) InsertParsedMessage(pm *domain.ParsedMessage) error
variables := Aviation_telegrams_insert_input{ variables := Aviation_telegrams_insert_input{
// Id: 10, // Id: 10,
Body_and_footer: pm.BodyAndFooter, Body_and_footer: pm.BodyAndFooter,
Body_data: string(bodyString), Body_data: bodyString,
Category: pm.Category, Category: pm.Category,
Date_time: pm.DateTime, Date_time: pm.DateTime,
Dispatched_at: pm.DispatchedAt, Dispatched_at: pm.DispatchedAt,
Uuid: uuid.New(), Uuid: uuid.New(),
Received_at: pm.ReceivedAt,
} }
_, err := newMessage(context.Background(), hr.client, variables) _, err := newMessage(context.Background(), hr.client, variables)
if err != nil { if err != nil {
+6 -84
View File
@@ -108,8 +108,7 @@ type aviation_telegrams {
category: String category: String
date_time: String date_time: String
dispatched_at: timestamp dispatched_at: timestamp
id: Int! message_id: String!
message_id: String
need_dispatch: Boolean need_dispatch: Boolean
originator: String originator: String
originator_date_time: String originator_date_time: String
@@ -136,17 +135,9 @@ type aviation_telegrams_aggregate {
aggregate fields of "aviation.telegrams" aggregate fields of "aviation.telegrams"
""" """
type aviation_telegrams_aggregate_fields { type aviation_telegrams_aggregate_fields {
avg: aviation_telegrams_avg_fields
count(columns: [aviation_telegrams_select_column!], distinct: Boolean): Int! count(columns: [aviation_telegrams_select_column!], distinct: Boolean): Int!
max: aviation_telegrams_max_fields max: aviation_telegrams_max_fields
min: aviation_telegrams_min_fields min: aviation_telegrams_min_fields
stddev: aviation_telegrams_stddev_fields
stddev_pop: aviation_telegrams_stddev_pop_fields
stddev_samp: aviation_telegrams_stddev_samp_fields
sum: aviation_telegrams_sum_fields
var_pop: aviation_telegrams_var_pop_fields
var_samp: aviation_telegrams_var_samp_fields
variance: aviation_telegrams_variance_fields
} }
"""append existing jsonb value of filtered columns with new jsonb value""" """append existing jsonb value of filtered columns with new jsonb value"""
@@ -155,11 +146,6 @@ input aviation_telegrams_append_input {
secondary_addresses: jsonb secondary_addresses: jsonb
} }
"""aggregate avg on columns"""
type aviation_telegrams_avg_fields {
id: Float
}
""" """
Boolean expression to filter rows from the table "aviation.telegrams". All fields are combined with a logical 'AND'. Boolean expression to filter rows from the table "aviation.telegrams". All fields are combined with a logical 'AND'.
""" """
@@ -172,7 +158,6 @@ input aviation_telegrams_bool_exp {
category: String_comparison_exp category: String_comparison_exp
date_time: String_comparison_exp date_time: String_comparison_exp
dispatched_at: timestamp_comparison_exp dispatched_at: timestamp_comparison_exp
id: Int_comparison_exp
message_id: String_comparison_exp message_id: String_comparison_exp
need_dispatch: Boolean_comparison_exp need_dispatch: Boolean_comparison_exp
originator: String_comparison_exp originator: String_comparison_exp
@@ -190,7 +175,7 @@ unique or primary key constraints on table "aviation.telegrams"
""" """
enum aviation_telegrams_constraint { enum aviation_telegrams_constraint {
""" """
unique or primary key constraint on columns "id" unique or primary key constraint on columns "message_id"
""" """
telegrams_pkey telegrams_pkey
@@ -224,13 +209,6 @@ input aviation_telegrams_delete_key_input {
secondary_addresses: String secondary_addresses: String
} }
"""
input type for incrementing numeric columns in table "aviation.telegrams"
"""
input aviation_telegrams_inc_input {
id: Int
}
""" """
input type for inserting data into table "aviation.telegrams" input type for inserting data into table "aviation.telegrams"
""" """
@@ -240,7 +218,6 @@ input aviation_telegrams_insert_input {
category: String category: String
date_time: String date_time: String
dispatched_at: timestamp dispatched_at: timestamp
id: Int
message_id: String message_id: String
need_dispatch: Boolean need_dispatch: Boolean
originator: String originator: String
@@ -259,7 +236,6 @@ type aviation_telegrams_max_fields {
category: String category: String
date_time: String date_time: String
dispatched_at: timestamp dispatched_at: timestamp
id: Int
message_id: String message_id: String
originator: String originator: String
originator_date_time: String originator_date_time: String
@@ -276,7 +252,6 @@ type aviation_telegrams_min_fields {
category: String category: String
date_time: String date_time: String
dispatched_at: timestamp dispatched_at: timestamp
id: Int
message_id: String message_id: String
originator: String originator: String
originator_date_time: String originator_date_time: String
@@ -314,7 +289,6 @@ input aviation_telegrams_order_by {
category: order_by category: order_by
date_time: order_by date_time: order_by
dispatched_at: order_by dispatched_at: order_by
id: order_by
message_id: order_by message_id: order_by
need_dispatch: order_by need_dispatch: order_by
originator: order_by originator: order_by
@@ -329,7 +303,7 @@ input aviation_telegrams_order_by {
"""primary key columns input for table: aviation.telegrams""" """primary key columns input for table: aviation.telegrams"""
input aviation_telegrams_pk_columns_input { input aviation_telegrams_pk_columns_input {
id: Int! message_id: String!
} }
"""prepend existing jsonb value of filtered columns with new jsonb value""" """prepend existing jsonb value of filtered columns with new jsonb value"""
@@ -357,9 +331,6 @@ enum aviation_telegrams_select_column {
"""column name""" """column name"""
dispatched_at dispatched_at
"""column name"""
id
"""column name""" """column name"""
message_id message_id
@@ -400,7 +371,6 @@ input aviation_telegrams_set_input {
category: String category: String
date_time: String date_time: String
dispatched_at: timestamp dispatched_at: timestamp
id: Int
message_id: String message_id: String
need_dispatch: Boolean need_dispatch: Boolean
originator: String originator: String
@@ -413,21 +383,6 @@ input aviation_telegrams_set_input {
uuid: uuid uuid: uuid
} }
"""aggregate stddev on columns"""
type aviation_telegrams_stddev_fields {
id: Float
}
"""aggregate stddev_pop on columns"""
type aviation_telegrams_stddev_pop_fields {
id: Float
}
"""aggregate stddev_samp on columns"""
type aviation_telegrams_stddev_samp_fields {
id: Float
}
""" """
Streaming cursor of the table "aviation_telegrams" Streaming cursor of the table "aviation_telegrams"
""" """
@@ -446,7 +401,6 @@ input aviation_telegrams_stream_cursor_value_input {
category: String category: String
date_time: String date_time: String
dispatched_at: timestamp dispatched_at: timestamp
id: Int
message_id: String message_id: String
need_dispatch: Boolean need_dispatch: Boolean
originator: String originator: String
@@ -459,11 +413,6 @@ input aviation_telegrams_stream_cursor_value_input {
uuid: uuid uuid: uuid
} }
"""aggregate sum on columns"""
type aviation_telegrams_sum_fields {
id: Int
}
""" """
update columns of table "aviation.telegrams" update columns of table "aviation.telegrams"
""" """
@@ -483,9 +432,6 @@ enum aviation_telegrams_update_column {
"""column name""" """column name"""
dispatched_at dispatched_at
"""column name"""
id
"""column name""" """column name"""
message_id message_id
@@ -536,9 +482,6 @@ input aviation_telegrams_updates {
""" """
_delete_key: aviation_telegrams_delete_key_input _delete_key: aviation_telegrams_delete_key_input
"""increments the numeric columns with given value of the filtered values"""
_inc: aviation_telegrams_inc_input
"""prepend existing jsonb value of filtered columns with new jsonb value""" """prepend existing jsonb value of filtered columns with new jsonb value"""
_prepend: aviation_telegrams_prepend_input _prepend: aviation_telegrams_prepend_input
@@ -549,21 +492,6 @@ input aviation_telegrams_updates {
where: aviation_telegrams_bool_exp! where: aviation_telegrams_bool_exp!
} }
"""aggregate var_pop on columns"""
type aviation_telegrams_var_pop_fields {
id: Float
}
"""aggregate var_samp on columns"""
type aviation_telegrams_var_samp_fields {
id: Float
}
"""aggregate variance on columns"""
type aviation_telegrams_variance_fields {
id: Float
}
"""user for test simple graphql""" """user for test simple graphql"""
type aviation_user { type aviation_user {
email: String! email: String!
@@ -859,7 +787,7 @@ type mutation_root {
""" """
delete single row from the table: "aviation.telegrams" delete single row from the table: "aviation.telegrams"
""" """
delete_aviation_telegrams_by_pk(id: Int!): aviation_telegrams delete_aviation_telegrams_by_pk(message_id: String!): aviation_telegrams
""" """
delete data from the table: "aviation.user" delete data from the table: "aviation.user"
@@ -940,9 +868,6 @@ type mutation_root {
""" """
_delete_key: aviation_telegrams_delete_key_input _delete_key: aviation_telegrams_delete_key_input
"""increments the numeric columns with given value of the filtered values"""
_inc: aviation_telegrams_inc_input
"""prepend existing jsonb value of filtered columns with new jsonb value""" """prepend existing jsonb value of filtered columns with new jsonb value"""
_prepend: aviation_telegrams_prepend_input _prepend: aviation_telegrams_prepend_input
@@ -975,9 +900,6 @@ type mutation_root {
""" """
_delete_key: aviation_telegrams_delete_key_input _delete_key: aviation_telegrams_delete_key_input
"""increments the numeric columns with given value of the filtered values"""
_inc: aviation_telegrams_inc_input
"""prepend existing jsonb value of filtered columns with new jsonb value""" """prepend existing jsonb value of filtered columns with new jsonb value"""
_prepend: aviation_telegrams_prepend_input _prepend: aviation_telegrams_prepend_input
@@ -1094,7 +1016,7 @@ type query_root {
""" """
fetch data from the table: "aviation.telegrams" using primary key columns fetch data from the table: "aviation.telegrams" using primary key columns
""" """
aviation_telegrams_by_pk(id: Int!): aviation_telegrams aviation_telegrams_by_pk(message_id: String!): aviation_telegrams
""" """
fetch data from the table: "aviation.user" fetch data from the table: "aviation.user"
@@ -1184,7 +1106,7 @@ type subscription_root {
""" """
fetch data from the table: "aviation.telegrams" using primary key columns fetch data from the table: "aviation.telegrams" using primary key columns
""" """
aviation_telegrams_by_pk(id: Int!): aviation_telegrams aviation_telegrams_by_pk(message_id: String!): aviation_telegrams
""" """
fetch data from the table in a streaming manner: "aviation.telegrams" fetch data from the table in a streaming manner: "aviation.telegrams"