Buy Me A Coffee

Edgedb Tuple Usage

2023-04-11

Edgedb is a modern database that supports the tuple data type. Tuple data type is used to represent combinations of different data types and this data structure can contain named or unnamed elements.

The Tuple data type is used to store combinations of multiple different data types. In edgedb, the tuple data type is defined using the keyword tuple. The following example defines an unnamed tuple instance, which contains a str and an int64 element:

SELECT ('Ali Veli', 35);

In this example, the expression ('Ali Veli', 35) represents a tuple data type. This tuple contains the name of a person “Ali Veli” as a str type and their age of 35 as an int64 type.

The tuple data type also supports named elements. Named tuple elements allow elements to be stored in a named way, making it easier to write more readable code. The following example defines a named tuple instance, which includes a str element named name and an int64 element named age:

SELECT (name := 'Ali Veli', age := 35);

In this example, the expression (name := 'Ali Veli', age := 35) represents a named tuple data type. This tuple contains the name of a person named “Ali Veli” as a str type and their age as an int64 type.

The tuple data type is frequently used in database operations. edgedb provides a set of specialized processor functions to handle tuples. These functions can be used to sort elements in a tuple, search for specific elements in a tuple, filter elements in a tuple, aggregate elements in a tuple, and perform many other operations on tuples.

The following examples demonstrate tuple operations in edgedb:

SELECT (35, 'Ali Veli') ORDER BY 1 DESC;

SELECT User FILTER User(name='Hatice')

SELECT (name := 'Hatice', age := 25, gender := 'Female')
FILTER age > 20 AND gender = 'Female';

SELECT User{name, age} FILTER User.age >= 18;

SELECT sum(User.age) FILTER User.age >= 18;

SELECT sum((10, 20), (30, 40)).0 AS total_sum;

These examples show some tuple operations. The first example is used to sort the elements inside a tuple. The second example is used to search for a specific element or elements in a named tuple. The third example is used to filter the elements inside a named tuple, and the last example is used to aggregate the elements inside a named tuple.

The tuple data type can also be used together with other data types. For example, the tuple data type can be stored in an array data type in Edgedb. The following example demonstrates storing a tuple in an array data type:

SELECT ['Ali Veli', 35];

In this example, the expression ['Ali Veli', 35] represents an array data type, and this array contains a str and an int64 element. The tuple in this example is stored among the elements of the array.

The tuple data type can also be used in conjunction with many other data types in edgedb. For example, tuples can be used in join operations in edgedb and are particularly useful for combining result sets that contain multiple data types. Tuples can also be used in other places such as function parameters and returned results in edgedb.



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 