• WithContext creates a new shallow copy of the current app with its context set to the given one.

    WithContext is often used to customize the default timeouts and/or group the execution duration of DB queries, transactions and any other app related operation.

    Keep in mind that this context will be used by all queries executed by the new app instance meaning that technically you can provide a context.Background() for no limits. Be careful with that!

    For example:

     ctx, cancel := context.WithTimeout(app.Context(), 5*time.Second)
    defer cancel()

    ctxApp := app.WithContext(ctx)

    // run your queries using the newly created ctxApp
    // (in the below example both the Find and Save operations share the same context)
    record, err := ctxApp.FindRecordById("example", "123")
    record.Set("name", "abc")
    err = ctxApp.Save(record)

    Parameters

    Returns App

Generated using TypeDoc