MCPcopy
hub / github.com/pocketbase/pocketbase / jsCreateTemplate

Method jsCreateTemplate

plugins/migratecmd/templates.go:74–101  ·  view source on GitHub ↗
(collection *core.Collection)

Source from the content-addressed store, hash-verified

72}
73
74func (p *plugin) jsCreateTemplate(collection *core.Collection) (string, error) {
75 // unset timestamp fields
76 collectionData, err := toMap(collection)
77 if err != nil {
78 return "", err
79 }
80 delete(collectionData, "created")
81 delete(collectionData, "updated")
82 deleteNestedMapKey(collectionData, "oauth2", "providers")
83
84 jsonData, err := marhshalWithoutEscape(collectionData, " ", " ")
85 if err != nil {
86 return "", fmt.Errorf("failed to serialize collection: %w", err)
87 }
88
89 const template = jsTypesDirective + `migrate((app) => {
90 const collection = new Collection(%s);
91
92 return app.save(collection);
93}, (app) => {
94 const collection = app.findCollectionByNameOrId(%q);
95
96 return app.delete(collection);
97})
98`
99
100 return fmt.Sprintf(template, string(jsonData), collection.Id), nil
101}
102
103func (p *plugin) jsDeleteTemplate(collection *core.Collection) (string, error) {
104 // unset timestamp fields

Callers 1

jsDiffTemplateMethod · 0.95

Calls 3

toMapFunction · 0.85
deleteNestedMapKeyFunction · 0.85
marhshalWithoutEscapeFunction · 0.85

Tested by

no test coverage detected