Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Building the home view

Querying the articles table

Here is a summary of the video transcript:

  • Introduction to SQL and Declarative Programming
    The video transitions from database migrations to interacting with the database using SQL. SQL is introduced as a declarative language where developers specify what they want, and the database determines how to execute it.

  • Defining SQL Queries with SQLC
    SQL queries are defined in .sql files with named annotations that instruct SQLC how to generate corresponding functions. Queries include fetching a single article by ID, retrieving multiple articles, and inserting a new article with a returned record.

  • Parameterized Queries and Security
    Placeholders such as $1 are used for parameterized queries, which help prevent SQL injection. The placeholder syntax varies depending on the database system being used.

  • Insert Operations with Automatic Timestamps
    The insert query specifies all required columns and uses database functions to generate timestamps automatically. The RETURNING * clause ensures the newly created record is returned after insertion.

  • Manual SQL Handling vs SQLC Automation
    Without SQLC, developers would need to manually write SQL execution logic, map results to structs, and handle errors. This process is error-prone and introduces significant boilerplate code.

  • Code Generation with SQLC
    Running SQLC generates Go code based on the defined SQL queries and configuration. It produces typed models, parameter structs, query methods, and a database interface to simplify and standardize database access.

  • Generated Database Interface and Usage
    SQLC generates an interface with methods such as Exec, Query, and QueryRow, along with support for transactions. A Queries struct provides access to all generated query methods through a constructor function.