/
database_value_impl.go
57 lines (49 loc) · 1.17 KB
/
database_value_impl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package core
//GoValue implementation for DatabaseIL.
func (db *DatabaseIL) GetGoMethod(name string) (*GoFunction, bool) {
switch name {
case "update_schema":
return WrapGoMethod(db.UpdateSchema), true
case "close":
return WrapGoMethod(db.Close), true
}
return nil, false
}
func (db *DatabaseIL) Prop(ctx *Context, name string) Value {
if db.ownerState == nil {
panic(ErrOwnerStateNotSet)
}
switch name {
case "schema":
if db.newSchemaSet.Load() {
return db.newSchema
}
return db.initialSchema
case "update_schema", "close":
default:
if db.schemaUpdateExpected {
if !db.schemaUpdated.Load() {
panic(ErrInvalidAccessSchemaNotUpdatedYet)
}
}
val, ok := db.topLevelEntities[name]
if ok {
perm := db.topLevelEntitiesAccessPermissions[name]
if err := ctx.CheckHasPermission(perm); err != nil {
panic(err)
}
return val
}
}
method, ok := db.GetGoMethod(name)
if !ok {
panic(FormatErrPropertyDoesNotExist(name, db))
}
return method
}
func (*DatabaseIL) SetProp(ctx *Context, name string, value Value) error {
return ErrCannotSetProp
}
func (db *DatabaseIL) PropertyNames(ctx *Context) []string {
return db.propertyNames
}