Skip to content

Commit

Permalink
Updated type module to star to avoid name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Jan 18, 2024
1 parent 27f8d3d commit ae55825
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dist/
.vscode
/clace
clace.db*
clace_app.db*
clace.toml
*.swp
.sw*
Expand Down
5 changes: 2 additions & 3 deletions internal/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
}
Expand Down
14 changes: 10 additions & 4 deletions internal/app/store/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strings"
"sync"
"time"

"github.com/claceio/clace/internal/app"
"github.com/claceio/clace/internal/utils"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/tests/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/app/util/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
DEFAULT_MODULE = "ace"
TYPE_MODULE = "type"
STARLARK_TYPE_MODULE = "star"
TABLE_MODULE = "table"
APP = "app"
PAGE = "page"
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/plugin_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ae55825

Please sign in to comment.