Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/deeper/data-management-in-fireback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ in the database.
Make this more professional please:


## Decide between 'one', 'object', and 'embed' types.
## Decide between 'one', 'object' types.

Fireback is generating some code, that developer had to write if he wanted to avoid half-measure. It
does not bring new ideas, just gathers them and make it easier to use.
Expand Down
13 changes: 0 additions & 13 deletions docs/docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ For example from license module:
You see that `permissions` is an array. **Important** It's important that, every array field to end
in plural english form. Some code might end up in mismatch for singular fields as a bug until 1.1.27.


## Type: object

Type on is also a nested field, which you can define `fields` very similarly in an array.
The difference is, there will be a one-2-one relation created on this type of data, besides
there will be an Addtional *Id field which would link them by a unique string id. At the moment,
Fireback is creating `id` auto incremental numeric for each table, as well as `uniqueId` as a unique
string identifier. `id` is intended to be used internally only for Fireback, and any external relationship
between data, needs to use `uniqueId` field instead (`unique_id` on database level). This might change,
as in large projects it causes large indexing tables.

For example, see array example, and instead of `type: array` use `type: object`. Other details are exactly the same.

## Type: one

The type one, is a specific type to Fireback. It means, you are targeting another table as a `one-to-one` relationship. The different with `object` is, in this type managing the data, deleting it is not depending
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-bed/src/sdk/modules/abac/UserEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class UserEntity extends BaseEntity {
{
"name": "primaryAddress",
"description": "User primary address location. Can be useful for simple projects that a user is associated with a single address.",
"type": "embed",
"type": "object",
"computedType": "UserPrimaryAddress",
"gormMap": {},
"-": "UserPrimaryAddress",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ entities:
# name: barcode
# description: "Product barcode"
# - name: meta
# type: embed
# type: object
# fields:
# - type: bool
# name: isEcoFriendly
Expand All @@ -111,7 +111,7 @@ entities:
# - type: bool
# name: isPreOrder
# description: "Marks if the product is available for pre-order"
# - type: embed
# - type: object
# name: more
# fields:
# - type: bool
Expand All @@ -132,6 +132,3 @@ entities:
# - type: bool
# name: isHandmade
# description: "Indicates if the product is handmade or artisan-crafted"



2 changes: 1 addition & 1 deletion modules/abac/AbacModule3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ entities:
type: string
description: User last connecting ip address
- name: primaryAddress
type: embed
type: object
description:
User primary address location. Can be useful for simple projects that a user is associated
with a single address.
Expand Down
4 changes: 2 additions & 2 deletions modules/abac/UserEntity.dyno.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type UserEntityQs struct {
StateOrProvince fireback.QueriableField `cli:"primary-address.state-or-province" table:"user" typeof:"string?" column:"state_or_province" qs:"stateOrProvince"`
PostalCode fireback.QueriableField `cli:"primary-address.postal-code" table:"user" typeof:"string?" column:"postal_code" qs:"postalCode"`
CountryCode fireback.QueriableField `cli:"primary-address.country-code" table:"user" typeof:"string?" column:"country_code" qs:"countryCode"`
} `cli:"primary-address" table:"user" column:"primary_address" typeof:"embed" qs:"primaryAddress" preload:"PrimaryAddress"`
} `cli:"primary-address" table:"user" column:"primary_address" typeof:"object" qs:"primaryAddress" preload:"PrimaryAddress"`
}

func (x *UserEntityQs) GetQuery() string {
Expand Down Expand Up @@ -443,7 +443,7 @@ Title: (type: string) Description:
BirthDate: (type: date) Description:
Avatar: (type: string) Description:
LastIpAddress: (type: string) Description: User last connecting ip address
PrimaryAddress: (type: embed) Description: User primary address location. Can be useful for simple projects that a user is associated with a single address.
PrimaryAddress: (type: object) Description: User primary address location. Can be useful for simple projects that a user is associated with a single address.
And here is the actual object signature:
` + v.Seeder() + `
`
Expand Down
4 changes: 2 additions & 2 deletions modules/fireback/cli-actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ func DatabaseColumnsResolver(
}

// Nested struct
if typeof == "one" || typeof == "object" || typeof == "array" || typeof == "collection" {
if typeof == "one" || typeof == "array" || typeof == "collection" {
if slices.Contains(requestedFields, qs) {
if preload != "" {
value.Preloads = append(value.Preloads, preload)
}
}

value = DatabaseColumnsResolver(fieldValue, fullName+".", requestedFields, value, false)
} else if typeof == "embed" {
} else if typeof == FIELD_TYPE_OBJECT {
if slices.Contains(requestedFields, qs) {
value = DatabaseColumnsResolver(fieldValue, fullName+".", requestedFields, value, true)
}
Expand Down
31 changes: 11 additions & 20 deletions modules/fireback/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ var FIELD_TYPE_ONE string = "one"
var FIELD_TYPE_DATE string = "date"
var FIELD_TYPE_COLLECTION string = "collection"
var FIELD_TYPE_OBJECT string = "object"
var FIELD_TYPE_EMBED string = "embed"
var FIELD_TYPE_MONEY string = "money?"
var FIELD_TYPE_XFILE string = "xfile?"
var FIELD_TYPE_ENUM string = "enum"
Expand Down Expand Up @@ -317,11 +316,11 @@ func (x *Module3Field) ComputedGormTag() string {
return "many2many:" + x.BelongingEntityName + "_" + x.PrivateName() + ";foreignKey:UniqueId;references:UniqueId"
}

if x.Type == FIELD_TYPE_EMBED || x.Type == FIELD_TYPE_MONEY {
if x.Type == FIELD_TYPE_OBJECT || x.Type == FIELD_TYPE_MONEY {
return "embedded"
}

if x.Type == FIELD_TYPE_ARRAY || x.Type == FIELD_TYPE_OBJECT {
if x.Type == FIELD_TYPE_ARRAY {
return "foreignKey:LinkerId;references:UniqueId;constraint:OnDelete:CASCADE"
}

Expand Down Expand Up @@ -362,7 +361,7 @@ func CalcAllPolyglotEntities(m []*Module3Field) []string {
items = append(items, item.Name)
}

if item.Type == FIELD_TYPE_OBJECT || item.Type == FIELD_TYPE_ARRAY {
if item.Type == FIELD_TYPE_ARRAY {
items = append(items, CalcAllPolyglotEntities(item.Fields)...)
}
}
Expand Down Expand Up @@ -1375,7 +1374,7 @@ func ComputeComplexGormField(entity *Module3Entity, fields []*Module3Field) {
for _, field := range fields {
field.BelongingEntityName = entity.Name

if field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_EMBED || field.Type == FIELD_TYPE_ARRAY {
if field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_ARRAY {
ComputeComplexGormField(entity, field.Fields)
}
}
Expand All @@ -1390,7 +1389,7 @@ func ComputeFieldTypes(fields []*Module3Field, isWorkspace bool, fn func(field *
for _, field := range fields {
field.ComputedType = fn(field, isWorkspace)

if field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_EMBED || field.Type == FIELD_TYPE_ARRAY {
if field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_ARRAY {
ComputeFieldTypes(field.Fields, isWorkspace, fn)
}
}
Expand All @@ -1406,7 +1405,7 @@ func ComputeFieldTypesAbsolute(fields []*Module3Field, isWorkspace bool, fn func
for _, field := range fields {
field.ComputedType = strings.ReplaceAll(fn(field, isWorkspace), "*", "")

if field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_EMBED || field.Type == FIELD_TYPE_ARRAY {
if field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_ARRAY {
ComputeFieldTypesAbsolute(field.Fields, isWorkspace, fn)
}
}
Expand Down Expand Up @@ -2410,11 +2409,11 @@ func GetArrayOrObjectFieldsFlatten(depth int, parentType string, depthName strin
}

for _, item := range fields {
if item.Type == FIELD_TYPE_EMBED {
if item.Type == FIELD_TYPE_OBJECT {
item.IsVirtualObject = true
}

if item.Type != FIELD_TYPE_OBJECT && item.Type != FIELD_TYPE_ARRAY && item.Type != FIELD_TYPE_EMBED {
if item.Type != FIELD_TYPE_ARRAY && item.Type != FIELD_TYPE_OBJECT {
item.ComputedType = ctx.Catalog.ComputeField(item, isWorkspace)
continue
} else {
Expand Down Expand Up @@ -2591,7 +2590,7 @@ func ImportDependecies(fields []*Module3Field) []ImportDependencyStrategy {
}
}

if field.Type == FIELD_TYPE_ARRAY || field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_EMBED {
if field.Type == FIELD_TYPE_ARRAY || field.Type == FIELD_TYPE_OBJECT {
items = append(items, ImportDependecies(field.Fields)...)
}

Expand Down Expand Up @@ -2691,7 +2690,7 @@ func ImportGoDependencies(fields []*Module3Field, importGroupPrefix string) []Im
// })
// }

if field.Type == FIELD_TYPE_ARRAY || field.Type == FIELD_TYPE_OBJECT || field.Type == FIELD_TYPE_EMBED {
if field.Type == FIELD_TYPE_ARRAY || field.Type == FIELD_TYPE_OBJECT {

items = append(items, ImportGoDependencies(field.Fields, actualPrefix)...)
}
Expand Down Expand Up @@ -3446,9 +3445,7 @@ func (x *Module3Entity) GetSqlFields() []string {
"template_entities.created_at",
}
for _, field := range x.Fields {
if field.Type == "object" {
continue
}

if field.Type == "one" {
items = append(items, "template_entities."+ToSnakeCase(field.Name)+"_id")
} else {
Expand All @@ -3463,9 +3460,6 @@ func (x *Module3Entity) GetSqlFields() []string {
func (x *Module3Entity) GetSqlFieldNames() []string {
items := []string{"parent_id", "visibility", "updated_at", "created_at"}
for _, field := range x.Fields {
if field.Type == "object" {
continue
}

if field.Type == "one" {
items = append(items, ToSnakeCase(field.Name)+"_id")
Expand All @@ -3486,9 +3480,6 @@ func (x *Module3Entity) GetSqlFieldNamesAfter() []string {
"template_entities_cte.created_at",
}
for _, field := range x.Fields {
if field.Type == "object" {
continue
}

if field.Type == "one" {
items = append(items, "template_entities_cte."+ToSnakeCase(field.Name)+"_id\n")
Expand Down
4 changes: 0 additions & 4 deletions modules/fireback/codegen/firebackgo/GoModuleDyno.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,6 @@ func {{ upper .Name }}Query(query {{ $.wsprefix}}QueryDSL) ([]*{{ template "quer
{{ if or (eq .Type "int32") }}
{{ upper $prefix }}{{ upper .Name }} int32 `envconfig:"{{- if .Env -}}{{ .Env }}{{else}}{{ snakeUpper .Name }}{{end}}" description:"{{ escape .Description}}"`
{{ end }}
{{ if or (eq .Type "object")}}
{{ $newPrefix := print $prefix .Name }}
{{ template "configFields" (arr .Fields $newPrefix)}}
{{ end }}
{{ end }}
{{ end }}

Expand Down
Loading
Loading