Types​

The properties of e that corresond to types—e.str, e.int64, etc— serve a dual purpose.

  • They can be used as functions to instantiate literals: e.str("hi").

  • They are also used to represent the type itself for certain type operations like casting and declaring parameters.

Reflected types​

The entire type system of EdgeDB is reflected in the e object, including scalar types, object types, and enums.

  1. e.str;
  2. e.bool;
  3. e.int16;
  4. e.int32;
  5. e.int64;
  6. e.float32;
  7. e.float64;
  8. e.bigin;
  9. e.decimal;
  10. e.datetime;
  11. e.duration;
  12. e.bytes;
  13. e.json;
  14. e.cal.local_datetime;
  15. e.cal.local_date;
  16. e.cal.local_time;
  17. e.cal.relative_duration;
  18. e.Movie; // user-defined object type
  19. e.Genre; // user-defined enum

Collection types​

Construct array and tuple types.

  1. e.array(e.bool);
  2. // array<bool>
  3. e.tuple([e.str, e.int64]);
  4. // tuple<str, int64>
  5. e.tuple({
  6. name: e.str,
  7. age: e.int64
  8. });
  9. // tuple<name: str, age: int64>

Casting​

These types can be used to cast one expression to another type.

  1. e.cast(e.json, e.int64('123'));
  2. // <json>'123'
  3. e.cast(e.duration, e.str('127 hours'));
  4. // <duration>'127 hours'

Custom literals​

You can use e.literal to create literals corresponding to collection types like tuples, arrays, and primitives. The first argument expects a type, the second expects a value of that type.

  1. e.literal(e.str, "sup");
  2. // equivalent to: e.str("sup")
  3. e.literal(e.array(e.int16), [1, 2, 3]);
  4. // <array<int16>>[1, 2, 3]
  5. e.literal(e.tuple([e.str, e.int64]), ['baz', 9000]);
  6. // <tuple<str, int64>>("Goku", 9000)
  7. e.literal(
  8. e.tuple({name: e.str, power_level: e.int64}),
  9. {name: 'Goku', power_level: 9000}
  10. );
  11. // <tuple<name: str, power_level: bool>>("asdf", false)

Parameters​

Types are also necessary for declaring query parameters.

Pass strongly-typed parameters into your query with e.params.

  1. const query = e.params({name: e.str}, params =>
  2. e.op(e.str("Yer a wizard, "), "++", params.name)
  3. );
  4. await query.run(client, {name: "Harry"});
  5. // => "Yer a wizard, Harry"

The full documentation on using parameters is here.