diff --git a/lcars/sqlite/description.md b/lcars/sqlite/description.md new file mode 100644 index 0000000..60f12e5 --- /dev/null +++ b/lcars/sqlite/description.md @@ -0,0 +1,35 @@ +# Features of the `sqlite` Go Package + +This is a summary of the key features provided by the `sqlite` package, based on an analysis of `database.go`. + +* **Simplified Database Lifecycle Management**: + * Provides straightforward functions to `New`, `Open`, `OpenInMemory`, and `Close` SQLite databases. + * Automatically creates a new database file if one doesn't exist, pre-configured with performance-oriented `PRAGMA` settings like `WAL` (Write-Ahead Logging) mode. + +* **Generic Data Handling**: + * Uses a `Record` type (`map[string]any`) to represent database rows, allowing for flexible interaction with tables without needing to define a struct for each one. + +* **High-Level CRUD Operations**: + * Offers simple methods for common database tasks: + * `ReadRecords`: Execute any `SELECT` query with parameters. + * `GetRecord`: Fetch a single record by its key. + * `UpsertRecord`: A powerful function to either `INSERT` a new record or `UPDATE` an existing one if a conflict on the primary key occurs. This is handled atomically in the database using `INSERT ... ON CONFLICT`. + * `DeleteRecord`: Remove a record by its key. + +* **Fluent Transaction API**: + * Implements a chainable transaction interface that simplifies running multiple operations in a single transaction. + * Example: `db.Begin().Next(action1).Next(action2).End()` + * The `End()` method automatically commits on success or rolls back if any step in the chain fails, ensuring data integrity. + +* **Database Introspection**: + * Includes helper functions to query database metadata, such as `TableList()` to get all table names, `Version()` for the SQLite engine version, and `UserVersion()` to manage schema versions. + +* **Abstraction and Safety**: + * Abstracts away the boilerplate of `database/sql` row scanning into `Rows2record` and `Rows2records` helpers. + * Uses parameterized queries to prevent SQL injection vulnerabilities for data values. + +* **Utility Functions**: + * Provides a generic `Value` function to safely extract and type-assert a value from a `Record`. + * Includes a `NoRowsOk` helper to gracefully handle queries that are expected to sometimes return no results, preventing "no rows found" from being treated as a critical error. + +This package is designed as a high-level wrapper around Go's standard `database/sql` library, specifically tailored for SQLite to make common database operations more convenient and less error-prone. diff --git a/slides/datastar/slides.md b/slides/datastar/slides.md index 21c6662..42cc025 100644 --- a/slides/datastar/slides.md +++ b/slides/datastar/slides.md @@ -128,10 +128,75 @@ transition: fade-out - Part 1: The Database: SQLite - Part 2: The No-ORM ORM - A very simple Data Abstraction Layer. - Part 3: Developing a Web Server Application in Go. -- Part 4: Datastar - lightweight framework for real-time collaborative web apps. +- Part 4: Datastar - a lightweight framework for real-time collaborative web apps. - Part 5: Modern CSS. - Part 6: Web components. -- Part 7: Simple Deployments with VPS, Nginx, certbot and a single binary file. +- Part 7: Simple Deployments with a VPS, Nginx, Certbot and a single binary file. + +--- +class: default +transition: fade-out +--- + +# Part 1: SQLite: +### It is fast, feature complete* and rock solid. +
+ +## It is not SQ-Lite, it is SQL-ite + + + +Since everybody knows SQLite, today just a few highlights: + +- It has JSON and JSONB as built-in data types. +- It has 29 new functions to extract from JSON or to create JSON objects. +- It's CTEs make SQL Turing complete. +- The SQLite CLI can be used to execute "SQL-scripts". See demo. + + + +