- 添加数据库连接与初始化逻辑 - 实现SQL查询结果扫描到结构体的功能 - 创建产品和分类表的初始数据脚本- 配置Go模块依赖及版本锁定文件 - 新增打印工具函数用于调试输出
26 lines
621 B
SQL
26 lines
621 B
SQL
drop table if exists Categories;
|
|
drop table if exists Products;
|
|
|
|
create table if not exists Categories (
|
|
Id integer not null primary key,
|
|
Name Text
|
|
);
|
|
|
|
create table if not exists Products (
|
|
Id integer not null primary key,
|
|
Name Text,
|
|
Category integer,
|
|
Price decimal(8,2),
|
|
constraint CatRef foreign key (Category) references Categories(Id)
|
|
);
|
|
|
|
insert into Categories(Id,Name)
|
|
values (1, 'Watersports'),
|
|
(2, 'Soccer');
|
|
|
|
insert into Products(Id,Name,Category,Price)
|
|
values (1, 'Kayak', 1, 275),
|
|
(2, 'Lifejacket', 1, 48.95),
|
|
(3, 'Soccer Ball', 2, 19.50),
|
|
(4, 'Corner Flags', 2, 34.95);
|