本教程将花费 5 到 10 分钟,最后,您将成功构建完整的 CRUD 应用程序。
本指南将向您展示如何构建“车辆维护日志”应用程序。对于本指南,我们将使用 PostgreSQL。在Budibase里,无论您使用什么类型的数据库,该过程都是相同的。
在本教程中,我们将创建一个车辆维护日志应用程序,其中包括:
CREATE TABLE public."Vehicles" (
"id" SERIAL PRIMARY KEY,
"Registration" TEXT NULL,
"Make" TEXT NULL,
"Model" TEXT NULL,
"Colour" TEXT NULL,
"Year" INT NULL);
CREATE TABLE public."ServiceLog" (
"id" SERIAL PRIMARY KEY,
"Description" TEXT NULL,
"VehicleId" INT NULL,
"ServiceDate" TIMESTAMP NULL,
"Category" TEXT NULL,
"Mileage" INT NULL);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('FAZ 9837','Volkswagen','Polo','White',2002);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('JHI 8827','BMW','M3','Black',2013);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('D903PI','Volvo','XC40','Grey',2014);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('YFI002','Volkswagen','Golf','Dark Blue',2018);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('HGT5677','Skoda','Octavia','Graphite',2009);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('PPF9276','Skoda','Octavia','Graphite',2021);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('J893FT','Toyota','Corolla','Red',2015);
INSERT INTO public."Vehicles"("Registration", "Make", "Model", "Colour", "Year")
VALUES ('MJK776','Honda','HR-V','Silver',2015);
INSERT INTO public."ServiceLog"("Description", "VehicleId", "ServiceDate", "Category", "Mileage")
VALUES ('Change front brakes', 1, '2021-05-04', 'Brakes', 20667);
INSERT INTO public."ServiceLog"("Description", "VehicleId", "ServiceDate", "Category", "Mileage")
VALUES ('Tyres - full set', 1, '2021-05-04', 'Tyres', 20667);
INSERT INTO public."ServiceLog"("Description", "VehicleId", "ServiceDate", "Category", "Mileage")
VALUES ('Engine tune up', 2, '2021-07-14', 'Engine', 50889);
INSERT INTO public."ServiceLog"("Description", "VehicleId", "ServiceDate", "Category", "Mileage")
VALUES ('Replace transmission', 3, '2021-09-26', 'Transmission', 98002);
一旦 Budibase 知道您的 SQL 表,它就可以自动生成屏幕(用户界面),允许列出、创建、编辑从表中删除记录。当然,这些生成的屏幕是完全可定制的——但 Budibase 为您提供了一个巨大的领先优势。
Budibase 允许您声明表之间的关系。我们将在 Vehicles 和 Deals 之间建立一对多的关系。
::: tip
Budibase 不会修改您的表格。我们只是告诉 Budibase 您现有的数据库结构。
:::
要定义关系:
9.选择您的 SQL 数据源
10. 单击定义关系,然后:
SELECT ServiceLogs.*, Registration as Vehicle
FROM ServiceLogs
INNER JOIN Vehicle on ServiceLog.VehicleId = Vehicle.id
更改显示列