A database table stores application records as rows under named columns. In a course service, a PostgreSQL table is created with a SQL script, seeded with test rows, and queried from Rust through a sqlx connection pool. section 4.2.2
/* Drop table if it already exists*/ drop table if exists ezy_course_c4; /* Create a table. */ /* Note: Don't put a comma after last field */ create table ezy_course_c4 ( course_id serial primary key, tutor_id INT not null, course_name varchar(140) not null, posted_time TIMESTAMP default now() ); /* Load seed data for testing */ insert into ezy_course_c4 (course_id,tutor_id, course_name,posted_time) values(1, 1, 'First course', '2020-12-17 05:40:00'); insert into ezy_course_c4 (course_id, tutor_id, course_name,posted_time) values(2, 1, 'Second course', '2020-12-18 05:45:00');
The initial course table defines an ID, required tutor and course fields, and a timestamp with a default; the script also inserts two test rows. section 4.2.2
Run the script against the target database, then use `select * from ezy_course_c4;` in psql to check the rows before connecting application code. A Rust `Course` struct holds the selected column values. section 4.2.2
/* Drop tables if they already exist*/
drop table if exists ezy_course_c6;
/* Create tables. */
/* Note: Don't put a comma after last field */
create table ezy_course_c6
(
course_id serial primary key,
tutor_id INT not null,
course_name varchar(140) not null,
course_description varchar(2000),
course_format varchar(30),
course_structure varchar(200),
course_duration varchar(30),
course_price INT,
course_language varchar(30),
course_level varchar(30),
posted_time TIMESTAMP default now()
);
The later course table adds columns for details such as description, format, price, and language. `NOT NULL` marks required fields; columns without it correspond to `Option<T>` fields in the Rust `Course` struct. section 6.2.1
Create tables before compiling SQL-backed APIs: sqlx checks referenced table and column names at compile time. The tutor APIs introduce a tutor table alongside the course table. section 6.3.4
In a PostgreSQL Docker container, psql calls tables “relations.” If `\d` finds none, run the initialization script, check that the tables and seed rows exist, then restart the container and query again to test persistence. section 12.3.2











