diff --git a/pq/message/format/delete.go b/pq/message/format/delete.go index ec84730..a6c09ca 100644 --- a/pq/message/format/delete.go +++ b/pq/message/format/delete.go @@ -8,11 +8,13 @@ import ( ) type Delete struct { - OldTupleData *tuple.Data - OldDecoded map[string]any - OID uint32 - XID uint32 - OldTupleType uint8 + OldTupleData *tuple.Data + OldDecoded map[string]any + OID uint32 + XID uint32 + OldTupleType uint8 + TableNamespace string + TableName string } func NewDelete(data []byte, streamedTransaction bool, relation map[uint32]*Relation) (*Delete, error) { @@ -26,6 +28,9 @@ func NewDelete(data []byte, streamedTransaction bool, relation map[uint32]*Relat return nil, errors.New("relation not found") } + msg.TableNamespace = rel.Namespace + msg.TableName = rel.Name + var err error msg.OldDecoded, err = msg.OldTupleData.DecodeWithColumn(rel.Columns) diff --git a/pq/message/format/delete_test.go b/pq/message/format/delete_test.go index 5ff7b34..2c33d8f 100644 --- a/pq/message/format/delete_test.go +++ b/pq/message/format/delete_test.go @@ -64,6 +64,8 @@ func TestDelete_New(t *testing.T) { "id": int32(645), "name": "foo", }, + TableNamespace: "public", + TableName: "t", } assert.Equal(t, expected, msg) diff --git a/pq/message/format/insert.go b/pq/message/format/insert.go index f7cfff2..738e05f 100644 --- a/pq/message/format/insert.go +++ b/pq/message/format/insert.go @@ -12,10 +12,12 @@ const ( ) type Insert struct { - TupleData *tuple.Data - Decoded map[string]any - OID uint32 - XID uint32 + TupleData *tuple.Data + Decoded map[string]any + OID uint32 + XID uint32 + TableNamespace string + TableName string } func NewInsert(data []byte, streamedTransaction bool, relation map[uint32]*Relation) (*Insert, error) { @@ -29,6 +31,9 @@ func NewInsert(data []byte, streamedTransaction bool, relation map[uint32]*Relat return nil, errors.New("relation not found") } + msg.TableNamespace = rel.Namespace + msg.TableName = rel.Name + msg.Decoded = make(map[string]any) var err error diff --git a/pq/message/format/insert_test.go b/pq/message/format/insert_test.go index a4b9def..a93d321 100644 --- a/pq/message/format/insert_test.go +++ b/pq/message/format/insert_test.go @@ -51,7 +51,9 @@ func TestInsert_New(t *testing.T) { }, SkipByte: 24, }, - Decoded: map[string]any{"id": int32(605), "name": "foo"}, + Decoded: map[string]any{"id": int32(605), "name": "foo"}, + TableNamespace: "public", + TableName: "t", } assert.EqualValues(t, expected, msg) diff --git a/pq/message/format/update.go b/pq/message/format/update.go index c5ed8a1..2862797 100644 --- a/pq/message/format/update.go +++ b/pq/message/format/update.go @@ -14,13 +14,15 @@ const ( ) type Update struct { - NewTupleData *tuple.Data - NewDecoded map[string]any - OldTupleData *tuple.Data - OldDecoded map[string]any - OID uint32 - XID uint32 - OldTupleType uint8 + NewTupleData *tuple.Data + NewDecoded map[string]any + OldTupleData *tuple.Data + OldDecoded map[string]any + OID uint32 + XID uint32 + OldTupleType uint8 + TableNamespace string + TableName string } func NewUpdate(data []byte, streamedTransaction bool, relation map[uint32]*Relation) (*Update, error) { @@ -34,6 +36,9 @@ func NewUpdate(data []byte, streamedTransaction bool, relation map[uint32]*Relat return nil, errors.New("relation not found") } + msg.TableNamespace = rel.Namespace + msg.TableName = rel.Name + var err error if msg.OldTupleData != nil { diff --git a/pq/message/format/update_test.go b/pq/message/format/update_test.go index 43a98fc..66d25e8 100644 --- a/pq/message/format/update_test.go +++ b/pq/message/format/update_test.go @@ -84,6 +84,8 @@ func TestUpdate_New(t *testing.T) { "id": int32(53), "name": "bar2", }, + TableNamespace: "public", + TableName: "t", } assert.Equal(t, expected, msg)