@@ -30,22 +30,25 @@ func NewAttemptDetailDao(db *sqlx.DB, bus *eventbus.EventBus, workspace bool) At
3030 }
3131}
3232
33- func (dao * attemptDetailDao ) Insert (ctx context.Context , attemptDetail * entities.AttemptDetail ) error {
34- ctx , span := tracing .Start (ctx , fmt .Sprintf ("dao.%s.insert " , dao .opts .Table ), trace .WithSpanKind (trace .SpanKindServer ))
33+ func (dao * attemptDetailDao ) BatchInsert (ctx context.Context , entities [] * entities.AttemptDetail ) error {
34+ ctx , span := tracing .Start (ctx , fmt .Sprintf ("dao.%s.batch_insert " , dao .opts .Table ), trace .WithSpanKind (trace .SpanKindServer ))
3535 defer span .End ()
3636
3737 now := time .Now ()
38- values := []interface {}{attemptDetail .ID , attemptDetail .RequestHeaders , attemptDetail .RequestBody , attemptDetail .ResponseHeaders , attemptDetail .ResponseBody , now , now , attemptDetail .WorkspaceId }
3938
40- sql := `INSERT INTO attempt_details (id, request_headers, request_body, response_headers, response_body, created_at, updated_at, ws_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
41- ON CONFLICT (id) DO UPDATE SET
42- request_headers = EXCLUDED.request_headers,
43- request_body = EXCLUDED.request_body,
44- response_headers = EXCLUDED.response_headers,
45- response_body = EXCLUDED.response_body,
46- updated_at = EXCLUDED.updated_at`
47-
48- result , err := dao .DB (ctx ).ExecContext (ctx , sql , values ... )
39+ builder := psql .Insert (dao .opts .Table ).Columns ("id" , "request_headers" , "request_body" , "response_headers" , "response_body" , "created_at" , "updated_at" , "ws_id" )
40+ for _ , entity := range entities {
41+ builder = builder .Values (entity .ID , entity .RequestHeaders , entity .RequestBody , entity .ResponseHeaders , entity .ResponseBody , now , now , entity .WorkspaceId )
42+ }
43+ sql , args := builder .Suffix (`
44+ ON CONFLICT (id) DO UPDATE SET
45+ request_headers = EXCLUDED.request_headers,
46+ request_body = EXCLUDED.request_body,
47+ response_headers = EXCLUDED.response_headers,
48+ response_body = EXCLUDED.response_body,
49+ updated_at = EXCLUDED.updated_at` ).MustSql ()
50+ dao .debugSQL (sql , args )
51+ result , err := dao .DB (ctx ).ExecContext (ctx , sql , args ... )
4952 if err != nil {
5053 return err
5154 }
0 commit comments