The Asqueel course

Understand the model.
Follow the code.

Choose a lesson and follow it step by step. Each lesson has its own page with the explanation, code and practice materials.

Module 01

Orientation

Meet the model. Build your first database object.

01Welcome: your first tableInstall Asqueel in a virtual environment, then create, query and change a product table in a Python console. No database files needed.Video · Notebook →02Customers, invoices and relationship pathsImport a product catalogue, customers and dated invoices from CSV. Import quantities, prices and totals, then read customer and product fields through relationship paths.Video · Notebook →03Filter and sort through relationshipsUse relationship paths in WHERE and ORDER BY, including two-hop filters and descending dates. Select only the fields you need.Video · Notebook →04Aliases and formula columnsGive a relationship path a short name, calculate each row's amount and see it change when the quantity changes.Video · Notebook →05Aggregate related recordsSummarize related records with invoice, customer and product totals, counts and averages; filter products by average selling price.Video · Notebook →06Group by and HAVINGSummarize sales by city with GROUP BY, SUM and COUNT; distinguish WHERE filters on rows from HAVING filters on groups.Video · Notebook →07Fetch and exportReuse the city report to choose Python result formats, retrieve records or keys, read batches and export CSV or JSON.Video · Notebook →08Optional: find the best buyerOptional exercise: group purchases to find a product's best buyer, then follow a weak relation from the calculated ID to the customer.Video · Notebook →09Writes and transactionsInsert, update and delete invoice rows, then use commit and rollback to control changes in the same in-memory database.Video · Notebook →10Python triggersCalculate and validate stored totals with Python hooks, compare normal writes with direct SQL, and undo changes in the same in-memory database.Video · Notebook →

Module 02

The model

Tables, relations, calculated columns and configuration.

11virtualRelationDeclare filtered to-many relations with virtualRelation, derive one from another, and link a table without a key relation.Reading · ~4 min →12Derived columns: aliasColumn, formulaColumnDeclare alias and formula columns, correlate sub-selects with #THIS, bind local values with var_*, and choose which virtual columns * returns.Reading · ~5 min →13Advanced formulasSupply formulas and sub-selects from Python methods of a table class, and read environment values inside a formula.Reading · ~4 min →14subQueryColumn and bagItemColumnDeclare collection and scalar sub-query columns, and read single items of an XML document stored in a column.Reading · ~4 min →15Layered recipesBuild one model from several recipes applied in order, and keep the connection in a deployment recipe.Reading · ~4 min →16Extending the grammarGive one table a column grammar with extra validated attributes, mounted through x_config.Reading · ~4 min →17The model hosts external metadataRead attributes of the model from application code and use them to drive an application task.Reading · ~3 min →

Module 03

Reading data

Write queries, bind values and choose the result shape.

18query(...): syntax and clausesWrite a SELECT with table.query() and predict the SQL it produces.Reading · ~7 min →19Parameters and macrosPass values to a query safely and use the macros #IN_RANGE, #PERIOD, #BAG and #BAGCOLS.Reading · ~7 min →20Fetch terminalsChoose the terminal that returns the rows in the shape you need.Reading · ~6 min →21The environmentSet context values for queries and writes, and know when they are read.Reading · ~5 min →22Row policiesDeclare partition, draft and logical-deletion policies, and control them per query.Reading · ~5 min →23Locking on read: for_updateLock the rows you read before you change them, on PostgreSQL and on SQLite.Reading · ~4 min →

Module 04

Writing data

Understand changes, triggers and relation actions.

24insert, update, deleteWrite single records with the three table commands and know what each one does with the record, the key and the database values.Reading · ~7 min →25The order of the write cycleKnow every step that insert, update and delete run, in their order, and how a hook refuses a write or starts another one.Reading · ~5 min →26Field triggersAttach write logic to a column with the six field-trigger attributes and trigger_table.Reading · ~4 min →27Relation actions: Python and SQLChoose between the Python actions onDelete/onUpdate and the SQL actions onDelete_sql/onUpdate_sql of a relation, and know when each one runs.Reading · ~5 min →28Writes without triggers: sql_*, table.lockWrite rows with the sql_* commands and the query terminals, which run only SQL, and lock a table.Reading · ~4 min →29sys_fields, hierarchical, auto_counterDeclare the three table options that add columns and the field triggers that fill them.Reading · ~5 min →30recordToUpdate and batchUpdateRead rows with a lock and write them back through the write cycle with two table helpers.Reading · ~4 min →

Module 05

Transactions & operations

Control connections, migrations and application integration.

31Transactions and connectionsComplete every unit of work explicitly, recover from errors, and select independent named connections.Reading · ~10 min →32Deferred callbacksSchedule work before and after a commit, block a commit on purpose, and recover when a callback fails.Reading · ~8 min →33Direct SQLExecute SQL text and compiled queries on the unit of work, and know what direct SQL skips.Reading · ~8 min →34Import and migrationsCreate and evolve the database from the recipe, and read an existing PostgreSQL catalog.Reading · ~10 min →35The command lineRegister a configuration folder, validate it, plan and apply migrations, and open a console from the terminal.Reading · ~8 min →36Integration in a host applicationDeclare asqueel databases inside a host configuration, own them by name in a server and its applications, and give every call a clean unit of work.Reading · ~9 min →37The complete exampleRun the course model end to end, from the recipe to a migrated database, writes, a reading query, an update and a delete.Reading · ~9 min →

Module 06

Other Python ORMs

Compare the concepts and make an informed choice.

38asqueel, SQLAlchemy, Django and PeeweeSee the same tasks in SQLAlchemy ORM, Django and Peewee and in asqueel, and know what asqueel does not provide.Reading · ~7 min →