MCPcopy Create free account
hub / github.com/fnproject/fn / InsertApp

Method InsertApp

api/datastore/sql/sql.go:310–351  ·  view source on GitHub ↗
(ctx context.Context, newApp *models.App)

Source from the content-addressed store, hash-verified

308}
309
310func (ds *SQLStore) InsertApp(ctx context.Context, newApp *models.App) (*models.App, error) {
311 app := newApp.Clone()
312 app.CreatedAt = common.DateTime(time.Now())
313 app.UpdatedAt = app.CreatedAt
314 app.ID = id.New().String()
315
316 if app.Config == nil {
317 // keeps the JSON from being nil
318 app.Config = map[string]string{}
319 }
320
321 query := ds.db.Rebind(`INSERT INTO apps (
322 id,
323 name,
324 config,
325 annotations,
326 syslog_url,
327 created_at,
328 updated_at,
329 shape
330 )
331 VALUES (
332 :id,
333 :name,
334 :config,
335 :annotations,
336 :syslog_url,
337 :created_at,
338 :updated_at,
339 :shape
340 );`)
341
342 _, err := ds.db.NamedExecContext(ctx, query, app)
343 if err != nil {
344 if ds.helper.IsDuplicateKeyError(err) {
345 return nil, models.ErrAppsAlreadyExists
346 }
347 return nil, err
348 }
349
350 return app, nil
351}
352
353func (ds *SQLStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.App, error) {
354 var app models.App

Callers

nothing calls this directly

Calls 6

DateTimeTypeAlias · 0.92
NewFunction · 0.92
NowMethod · 0.80
IsDuplicateKeyErrorMethod · 0.65
CloneMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected