Week 44 / 2022

Mohamed Saif published on
5 min, 878 words

GO: resources

Docker

  • Install System Dependencies casuse error, hash sum mismatch? issue. temp solution, remove this line apt-get install -y netcat gcc from the Dockerfile.

Edgedb

  • It’s common to declare the entire schema in a single file, dbschema/default.esdl.
  • Abstract types don’t have any concrete footprints in the database, as they don’t hold any actual data. Their only job is to propagate properties, links, and constraints to the types that extend them.
  • edgedb migration create, then edgedb migrate
  • An array is a collection of the same type.
  • low-level (DDL commands pertaining to migrations.) migration:
  1. start migration to {module [module-name] {type [type-name]; type [type-name];};};
  2. describe current migration;
  3. populate migration;
  4. commit migration;
  • := to declare, = for check equality, and !=.
  • EdgeDB doesn’t have null: where you would have null in other languages, EdgeDB just gives you an empty set: {}.
  • with x = "hello", select x != "world" # output: { true }
  • strs are fine with unicode letters (like emojis). EdgeDB also has a byte literal type that gives you the bytes of a string. They are 1 byte long. only ASCII works for this type.
  • select [Type] {property, ..} vs select [Type].single-property (path).
  • rename the property name using select and :=, select [Type] {new-name := .property, }.
  • EdgeDB is strongly typed: everything needs a type and it will not try to mix them together. And it can use “type inference” to guess the type
  • multi link = one-to-many. single link = one-to-one
  • enum is about making one choice between options. The variants of the enum should be written in UpperCamelCase.
  • scalar type only holds a single value at a time. object types can hold multiple values at the same time. extending, to take a type as a base and extend it. We can’t insert it directly to abstract type, and select on an abstract type is just fine - it will select all the types that extend from it.
  • Notice, you can not make a non-empty type abstract, Error: ConstraintViolationError: may not make non-empty object type 'default::Person' abstract
  • Casting means to quickly change one type into another, use <[Type]> to do the cast yourself.
  • casting is only for scalar types, user-created object types are very complex for casting.
  • selecr [Type]{} filter .[property] [operator] [value];
  • sensitive like, and in-sensitive ilike. % match anything before/after.
  • string indexing and slicing: filter .name[0] = "S";, filter .name[0:2] = "Sai";, BUT like and ilike are faster than indexing and slicing.
  • The brackets (parentheses): to capture the result of the query using SELECT, so that its result can be used as a whole. EdgeDB will do the operation inside the brackets, and then that completed result is given to [property/variable].
  • constraints: gives users fine-grained control over which data is considered valid. The can be defined on properties, links, object types?, and custom scalars.
  • usernames must be unique: type user {required property username -> str {constraint exclusive;}}.
  • The expression constraint is used to define custom constraint logic. Inside custom constraints, the keyword __subject__ can used to reference the value being constrained: constraint expression on (len(__subject__) <= 25).
  • delete [type] deletes every object for the this type.
  • DELETE statements in EdgeDB are actually syntactic sugar for DELETE (SELECT ...).
  • std::assert_single(s: set of anytype, named only message -> optional str = <str>{}) -> set of anytype, An optional message named argument can be used to customize the error message instead of raising a CardinalityViolationError.
  • DETACHED in the insert query, to specify that we are talking about the Type in general, not the object that we are inserting right now.
  • Computed properties and links are not persisted in the database. Instead, they are evaluated on the fly whenever that field is queried.
Questions
  • pydantic and edgedb? You are not forced to use Pydantic schemas. A minimum option is generate the JSON response directly with the queries inside EdgeDB and send it out, in that case maybe Starlette is enough instead of FastAPI. In my case I used Pydantic schemas to get all the FastAPI benefits like data validation and auto-documentation.
  • edgedb error: TransactionError: current transaction is aborted, commands ignored until end of transaction block? abort migration abort the migration block and discard the migration. BUT, what is the transaction block? use rollback; to roll back the current transaction and causes all updates made by the transaction to be discarded.
  • Why he doesn't make any migrations?

Reading: Deep Work

  • Deep Work: Professional activities performed in a state of distraction-free concentration that push your cognitive capabilities to their limit. These efforts create new value, improve your skill, and are hard to replicate.
  • The reason knowledge workers are losing their familiarity with deep work is well established: network tools.
  • Shallow Work: Noncognitively demanding, logistical-style tasks, often performed while distracted. These efforts tend to not create much new value in the world and are easy to replicate.