Buy Me A Coffee

Edgedb Enums

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 İlişkiler

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

Edgedb’de iki tablo arasında ilişki kurmak için link anahtar kelimesi kullanılır. Linkler, bir objenin başka bir objeyle ilişkilendirilmesine izin verir. Örneğin, bir User tablosu ve bir Article tablosu varsa, Article tablosundaki her bir Article, bir Userya atfedilebilir. Bu durumda, User ve Article tabloları arasında bir ilişki kurabiliriz. İlk olarak, User tablosunda bir id özelliği tanımlarız. Bu özellik, kullanıcının benzersiz bir kimliğini temsil eder. type User { required property id -> uuid; property name -> str; } Ardından, Article tablosunda bir author özelliği tanımlarız.

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 