Struct

Introduction

In D3E Studio, structs serve as a way to define a structure for holding data, similar to models. However, there are some key differences between structs and models.

Cannot Be Stored in DB

One significant distinction is that structs cannot be stored in the database (DB). They are typically used for temporary data holding and passing data between different parts of the application.

Use Cases

Structs are employed in various scenarios for managing and transporting data:

Server to Client Communication: Structs can be utilized to send data from the server to the client, providing a way to organize and convey information.

Widget to Widget Communication: When one widget needs to send data to another widget, structs can serve as a structured format for passing information between these widgets.

Temporary Data Holding: In classes or methods where temporary data needs to be held or manipulated, structs provide a convenient and lightweight way to structure the data without the need for persistent storage.

Key Components of Structs:

Name:

  • Every struct is uniquely identified by a name within project.

Description:

  • Here you can give a detailed and informative explanation or representation of Struct. It is a narrative that provides additional information to help understand, identify, or explain about the struct.

Properties:

  • Describes the attributes or fields of the data object.
  • Specifies the various characteristics and data types associated with the struct.
  • Each property encapsulates a specific piece of data within the object, providing a structured way to organize and describe the information.

Documentation

  • Allows users to document and store information about specific Struct in the project. Write notes, explanations, or guidelines related to Struct. Facilitates collaboration by providing a shared space for notes and documentation.

Key Components of Properties:

Name:

  • The name of the property serves as its identity within the struct. It uniquely identifies the specific data field.

Type:

  • The type of a property specifies the kind of data it can hold. It can be a primitive data type, another model, or an option set.

  • Significance: Type define the nature of the data the property can store, ensuring consistency and enabling D3E Studio to generate appropriate backend structures.

      - name: "firstName"
          type: "String"
      - name: "age"
          type: "Integer"
      - name: "Address"
          type: "AddressModel"  # Another model as a type
      - name: "Gender"
          type: "GenderOptionSet"  # Option set as a type

This property is a multiple entry/Collection

  • The "collection" property in D3E Studio struct indicates that a particular property can hold multiple values, essentially turning it into a list or an array. This is useful when a property needs to represent a collection of items rather than a single value.

  • Significance: Marking a property as a collection allows it to store multiple instances of the specified type, accommodating scenarios where multiple items are associated with a single entity.

      properties:
      - name: "subjects"
          type: "Subject"
          collection: true
      - name: "Mobile Number"
          type: "Integer"
          collection: true
      - name: "Awards"
          type: "String"
          collection: false

Description

  • Here you can give a detailed and informative explanation or representation of a Struct Property. It is a narrative that provides additional information to help understand, identify, or explain about the property.

Computed

A computed struct is a data structure created by performing computations or aggregations on the members of one or more source structs. It encapsulates derived information, allowing developers to organize and access calculated values in a structured manner.

Internal

An internal struct is a composite data type within a software module or program that is designed to encapsulate related variables under a single entity. Unlike public structs, an internal struct is deliberately kept private, and its details are not exposed to external users or other parts of the program.

Creating a Struct

  • Step 1: Select Struct in "Create New" button.

  • Step 2: Give a unique name to the Struct.

  • Step 3: Give the description for the Struct (Optional).

  • Step 4: Create property.

  • Step 5: Give a unique name to the Struct property.

  • Step 6: Select a data type from the available list.

  • Step 7: Enable collection checkbox, for collection values (if needed).

  • Step 8: Give a description about struct property (if needed).

  • Step 9: Enable Computed checkbox, for computed values (if needed) and write your computation code.

  • Step 10: Enable Internal if you need struct as internal.

  • Step 11: Click on save, Check whether struct is saved or not in the structs list in the Explore tree.

Managing Struct

Property:

To duplicate, edit, delete property, navigate to the respective section in the Option set editor, locate the item you want to duplicate, edit, delete and use the provided options to duplicate or edit it or if that property is no longer needed delete it.

Structs in D3E Studio provide a flexible and efficient way to structure and pass data between different parts of an application without the need for persistent storage. They are particularly useful in scenarios where temporary data needs to be managed or communicated between various components and layers of the application.