Edgedb Enums

[tr] Türkçe Oku

2023-04-11

Edgedb allows users to define enums and use them in data modeling. Enums are one of the data types we use to store data. An enum is a data structure that contains a specific set of constant values. These constants can be used to limit the values of a field in the data model. This can help prevent storing incorrect or invalid data in the model and provide application developers with a more precise and secure data modeling experience.

In Edgedb, enums are defined as a special data type, and the following syntax is used to define an enum

enum <enum_name> {
    <enum_value_1> := <value_1>,
    <enum_value_2> := <value_2>,
    ...
}

In this example, the <enum_name> element specifies the name of the enum to be defined. The <enum_value_1> and <enum_value_2> elements specify the names of the enum constants and their values are specified using the := symbol.

The following example defines an enum called user_role, which contains three different constant values: admin, editor, and viewer:

enum user_role {
    admin := 'admin',
    editor := 'editor',
    viewer := 'viewer'
}

Enum constants can be used as the default value of a field, and that field can only take the values of the enum constants. The following example defines an object type called User, which includes a field called role. This field takes a constant value from the user_role enum:

type User {
    required property name -> str;
    required property email -> str;
    property role -> user_role;
}

This example specifies that the role field of the User object type can only take the values of admin, editor, or viewer, which are the constants of the user_role enum.

Enums are a very useful tool to ensure consistency in data modeling operations. Thanks to its support for enums, Edgedb can prevent storing incorrect data and provide application developers with a more precise and secure data modeling experience, making the data easier to understand.



More posts like this

Edgedb Computed Links

2023-04-12 | #edgedb #edgedb-links

Computed Links is a structure used to define relationships between two objects. These links are created by using a defined query or function to calculate the relationship between associated objects. Computed Links is a structure used to define relationships between two objects. These connections are created by using a defined query or function to calculate the relationship between the associated objects. This structure is very useful for ensuring consistency of the data held in the database.

Continue reading 


Edgedb Exclusive Constraint

2023-04-12 | #edgedb #edgedb-constraints

The term exclusive constraint in EdgeDB refers to a type of constraint that ensures a specific property is unique or within a certain range. For example, you can create an exclusive constraint in a User object that ensures the email property is unique, thus ensuring that each user is only saved once. In the following example, we are defining an exclusive constraint that ensures uniqueness in the email property: type User { required property id -> uuid; required property name -> str; exclusive constraint unique_email on (.

Continue reading 


Edgedb Constraints

2023-04-11 | #edgedb #edgedb-constraints

Edgedb is a relational database management system (RDBMS) that provides various constraint mechanisms to securely store and manage your data while preserving the integrity of the data recorded in your database. Constraints are a set of rules used to maintain the integrity of the data stored in your database. There are five different types of constraint: 1. Primary Key Constraints: Primary key constraints ensure that each row is uniquely identified. This constraint specifies that there can only be one primary key column in a table, and each value in this column can only be used once.

Continue reading 