Buy Me A Coffee

Edgedb Exclusive Constraint

2023-04-12

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 (.email);
  property email -> str;
}

In this example, we defined a “unique_email” exclusive constraint for the User object, which ensures uniqueness in the email property. The on keyword is used to specify which property should be unique. In this case, we specified the email property using .email.

Constraints can include multiple properties and enforce uniqueness on combinations of these properties. For example, if you want to enforce uniqueness on the combination of email and phone properties for a User object, you can define a unique constraint as shown in the following example:

type User {
  required property id -> uuid;
  required property name -> str;
  exclusive constraint unique_email_phone on (.email, .phone);
  property email -> str;
  property phone -> str;
}

In this example, we defined a “unique_email_phone” exclusive constraint for the User object. This constraint ensures uniqueness in the combination of the email and phone properties.



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 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 