MCPcopy
hub / github.com/pocketbase/pocketbase / RecordQuery

Method RecordQuery

core/record_query.go:26–165  ·  view source on GitHub ↗

RecordQuery returns a new Record select query from a collection model, id or name. In case a collection id or name is provided and that collection doesn't actually exists, the generated query will be created with a cancelled context and will fail once an executor (Row(), One(), All(), etc.) is call

(collectionModelOrIdentifier any)

Source from the content-addressed store, hash-verified

24// actually exists, the generated query will be created with a cancelled context
25// and will fail once an executor (Row(), One(), All(), etc.) is called.
26func (app *BaseApp) RecordQuery(collectionModelOrIdentifier any) *dbx.SelectQuery {
27 var tableName string
28
29 collection, collectionErr := getCollectionByModelOrIdentifier(app, collectionModelOrIdentifier)
30 if collection != nil {
31 tableName = collection.Name
32 }
33 if tableName == "" {
34 // update with some fake table name for easier debugging
35 tableName = "@@__invalidCollectionModelOrIdentifier"
36 }
37
38 query := app.ConcurrentDB().Select(app.ConcurrentDB().QuoteSimpleColumnName(tableName) + ".*").From(tableName)
39
40 // in case of an error attach a new context and cancel it immediately with the error
41 if collectionErr != nil {
42 ctx, cancelFunc := context.WithCancelCause(context.Background())
43 query.WithContext(ctx)
44 cancelFunc(collectionErr)
45 }
46
47 return query.WithBuildHook(func(q *dbx.Query) {
48 q.WithExecHook(execLockRetry(app.config.QueryTimeout, defaultMaxLockRetries)).
49 WithOneHook(func(q *dbx.Query, a any, op func(b any) error) error {
50 if a == nil {
51 return op(a)
52 }
53
54 switch v := a.(type) {
55 case *Record:
56 record, err := resolveRecordOneHook(collection, op)
57 if err != nil {
58 return err
59 }
60
61 *v = *record
62
63 return nil
64 case RecordProxy:
65 record, err := resolveRecordOneHook(collection, op)
66 if err != nil {
67 return err
68 }
69
70 v.SetProxyRecord(record)
71 return nil
72 default:
73 return op(a)
74 }
75 }).
76 WithAllHook(func(q *dbx.Query, sliceA any, op func(sliceB any) error) error {
77 if sliceA == nil {
78 return op(sliceA)
79 }
80
81 switch v := sliceA.(type) {
82 case *[]*Record:
83 records, err := resolveRecordAllHook(collection, op)

Callers 15

FindAllOTPsByRecordMethod · 0.95
FindOTPByIdMethod · 0.95
DeleteExpiredOTPsMethod · 0.95
FindRecordByIdMethod · 0.95
FindRecordsByIdsMethod · 0.95
FindAllRecordsMethod · 0.95
FindFirstRecordByDataMethod · 0.95
FindRecordsByFilterMethod · 0.95
CountRecordsMethod · 0.95
FindAuthRecordByEmailMethod · 0.95
CanAccessRecordMethod · 0.95

Calls 13

ConcurrentDBMethod · 0.95
execLockRetryFunction · 0.85
opFunction · 0.85
resolveRecordOneHookFunction · 0.85
resolveRecordAllHookFunction · 0.85
SelectMethod · 0.80
QuoteSimpleColumnNameMethod · 0.80
AppendMethod · 0.80
dereferenceFunction · 0.70
SetProxyRecordMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected