MCPcopy Index your code
hub / github.com/bytebase/bytebase / CreateQueryHistory

Method CreateQueryHistory

backend/store/query_history.go:65–106  ·  view source on GitHub ↗

CreateQueryHistory creates the query history.

(ctx context.Context, create *QueryHistoryMessage)

Source from the content-addressed store, hash-verified

63
64// CreateQueryHistory creates the query history.
65func (s *Store) CreateQueryHistory(ctx context.Context, create *QueryHistoryMessage) (*QueryHistoryMessage, error) {
66 payload, err := protojson.Marshal(create.Payload)
67 if err != nil {
68 return nil, err
69 }
70
71 q := qb.Q().Space(`
72 INSERT INTO query_history (
73 creator,
74 project,
75 database,
76 statement,
77 type,
78 payload
79 )
80 VALUES (?, ?, ?, ?, ?, ?)
81 RETURNING
82 resource_id,
83 created_at
84 `,
85 create.Creator,
86 create.Project,
87 create.Database,
88 create.Statement,
89 create.Type,
90 payload,
91 )
92
93 sql, args, err := q.ToSQL()
94 if err != nil {
95 return nil, errors.Wrapf(err, "failed to build sql")
96 }
97
98 if err := s.GetDB().QueryRowContext(ctx, sql, args...).Scan(
99 &create.ResourceID,
100 &create.CreatedAt,
101 ); err != nil {
102 return nil, err
103 }
104
105 return create, nil
106}
107
108// ListQueryHistories lists the query history.
109func (s *Store) ListQueryHistories(ctx context.Context, find *FindQueryHistoryMessage) ([]*QueryHistoryMessage, error) {

Callers 1

createQueryHistoryMethod · 0.80

Calls 5

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
ToSQLMethod · 0.80
ScanMethod · 0.80

Tested by

no test coverage detected