refactored automigrate to be more granular

This commit is contained in:
Gani Georgiev
2022-11-27 23:00:58 +02:00
parent 3bce173748
commit 7ac3a74440
4 changed files with 649 additions and 43 deletions
+17
View File
@@ -9,6 +9,7 @@ import (
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/models/schema"
)
func NewBaseVM(app core.App) *goja.Runtime {
@@ -33,6 +34,7 @@ func NewBaseVM(app core.App) *goja.Runtime {
collectionConstructor(vm)
recordConstructor(vm)
adminConstructor(vm)
schemaConstructor(vm)
daoConstructor(vm)
dbxBinds(vm)
@@ -66,6 +68,21 @@ func adminConstructor(vm *goja.Runtime) {
})
}
func schemaConstructor(vm *goja.Runtime) {
vm.Set("Schema", func(call goja.ConstructorCall) *goja.Object {
instance := &schema.Schema{}
instanceValue := vm.ToValue(instance).(*goja.Object)
instanceValue.SetPrototype(call.This.Prototype())
return instanceValue
})
vm.Set("SchemaField", func(call goja.ConstructorCall) *goja.Object {
instance := &schema.SchemaField{}
instanceValue := vm.ToValue(instance).(*goja.Object)
instanceValue.SetPrototype(call.This.Prototype())
return instanceValue
})
}
func daoConstructor(vm *goja.Runtime) {
vm.Set("Dao", func(call goja.ConstructorCall) *goja.Object {
db, ok := call.Argument(0).Export().(dbx.Builder)