diff --git a/.gitignore b/.gitignore index ba66d4a..57747cd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ dist/ .vscode /clace clace.db* +clace_app.db* clace.toml *.swp .sw* diff --git a/internal/app/setup.go b/internal/app/setup.go index 830f48c..490318d 100644 --- a/internal/app/setup.go +++ b/internal/app/setup.go @@ -144,10 +144,10 @@ func (a *App) addSchemaTypes(builtin starlark.StringDict) (starlark.StringDict, } typeModule := starlarkstruct.Module{ - Name: util.TYPE_MODULE, + Name: util.STARLARK_TYPE_MODULE, Members: typeDict, } - newBuiltins[util.TYPE_MODULE] = &typeModule + newBuiltins[util.STARLARK_TYPE_MODULE] = &typeModule // Add table module for referencing table names tableDict := starlark.StringDict{} @@ -160,7 +160,6 @@ func (a *App) addSchemaTypes(builtin starlark.StringDict) (starlark.StringDict, Members: tableDict, } newBuiltins[util.TABLE_MODULE] = &tableModule - a.Trace().Msgf("********Added %d types to builtins", len(a.storeInfo.Types)) return newBuiltins, nil } diff --git a/internal/app/store/sql_store.go b/internal/app/store/sql_store.go index 698c7e4..0baa9a6 100644 --- a/internal/app/store/sql_store.go +++ b/internal/app/store/sql_store.go @@ -10,6 +10,7 @@ import ( "os" "strings" "sync" + "time" "github.com/claceio/clace/internal/app" "github.com/claceio/clace/internal/utils" @@ -128,6 +129,9 @@ func (s *SqlStore) Insert(collection string, entry *Entry) (EntryId, error) { return -1, err } + entry.CreatedAt = time.Now() + entry.CreatedBy = "admin" // TODO update userid + var err error collection, err = s.genTableName(collection) if err != nil { @@ -140,7 +144,7 @@ func (s *SqlStore) Insert(collection string, entry *Entry) (EntryId, error) { } createStmt := "INSERT INTO " + collection + " (version, created_by, updated_by, created_at, updated_at, data) VALUES (?, ?, ?, ?, ?, ?)" - result, err := s.db.Exec(createStmt, entry.Version, entry.CreatedBy, entry.UpdatedBy, entry.CreatedAt, entry.UpdatedAt, dataJson) + result, err := s.db.Exec(createStmt, entry.Version, entry.CreatedBy, entry.UpdatedBy, entry.CreatedAt.Unix(), entry.UpdatedAt.Unix(), dataJson) if err != nil { return -1, nil } @@ -167,10 +171,10 @@ func (s *SqlStore) SelectById(collection string, key EntryId) (*Entry, error) { query := "SELECT id, version, created_by, updated_by, created_at, updated_at, data FROM " + collection + " WHERE id = ?" row := s.db.QueryRow(query, key) - var dataStr string entry := &Entry{} - - err = row.Scan(&entry.Id, &entry.Version, &entry.CreatedBy, &entry.UpdatedBy, &entry.CreatedAt, &entry.UpdatedAt, dataStr) + var dataStr string + var createdAt, updatedAt int64 + err = row.Scan(&entry.Id, &entry.Version, &entry.CreatedBy, &entry.UpdatedBy, &createdAt, &updatedAt, &dataStr) if err != nil { if err == sql.ErrNoRows { return nil, fmt.Errorf("entry %d not found in collection %s", key, collection) @@ -184,6 +188,8 @@ func (s *SqlStore) SelectById(collection string, key EntryId) (*Entry, error) { } } + entry.CreatedAt = time.Unix(createdAt, 0) + entry.UpdatedAt = time.Unix(updatedAt, 0) return entry, nil } diff --git a/internal/app/tests/basic_test.go b/internal/app/tests/basic_test.go index b8e145e..02fb2ba 100644 --- a/internal/app/tests/basic_test.go +++ b/internal/app/tests/basic_test.go @@ -445,7 +445,7 @@ type("mytype", fields=[ app = ace.app("testApp", custom_layout=True, pages = [ace.page("/")]) def handler(req): - myt = type.mytype(aint=1, astring="abc", alist=[1,2,3], adict={"a": 1, "b": 2}, abool=False) + myt = star.mytype(aint=1, astring="abc", alist=[1,2,3], adict={"a": 1, "b": 2}, abool=False) myt.aint=2 myt.astring="abc2" myt.abool=True diff --git a/internal/app/util/builtins.go b/internal/app/util/builtins.go index 81fe605..fb96d0f 100644 --- a/internal/app/util/builtins.go +++ b/internal/app/util/builtins.go @@ -15,7 +15,7 @@ import ( const ( DEFAULT_MODULE = "ace" - TYPE_MODULE = "type" + STARLARK_TYPE_MODULE = "star" TABLE_MODULE = "table" APP = "app" PAGE = "page" diff --git a/internal/utils/plugin_response.go b/internal/utils/plugin_response.go index 85ecb9d..357985e 100644 --- a/internal/utils/plugin_response.go +++ b/internal/utils/plugin_response.go @@ -78,7 +78,7 @@ func (r *PluginResponse) Freeze() { } func (r *PluginResponse) Truth() starlark.Bool { - return r.errorCode != 0 + return r.err == nil } func (r *PluginResponse) Hash() (uint32, error) {