Generating Schemas

Generating database schemas using generative AI

Schema in regards to generation is about creating the schemas that project structures client side forms, API services, and databases use to ensure data follows a certain pattern.

Example: Creating Schemas for a Bicycle Rental Application's Booking Feature

How schemas can be used to ensure consistent data patterns in a bicycle rental application's booking feature.

Prompt

chatgpt-3.5:
create a schema for a bike rental order form

Response

import { object, string, date, number, array } from 'yup';

const rentalSchema = object({
  name: string().required(),
  email: string().email().required(),
  startDate: date().required(),
  endDate: date().required(),
  bikeType: string().required(),
  quantity: number().integer().required(),
  options: array(string()),
  cardNumber: string().length(16).required(),
  cardExpiration: date().min(new Date()).required(),
  cardCvv: string().length(3).required(),
});

In this example, we're using the yup library to define a schema for the data that is collected when a customer books a bicycle rental. The object function creates an object schema, and the various string, date, number, and array functions are used to define the data types and validation rules for each field.

Discussion:

The use of schemas in a bicycle rental application's booking feature can greatly improve the quality and consistency of data across the application. By using schemas to define data patterns and validation rules, developers can ensure that data is stored and used correctly, and that errors and bugs are caught early in the development process. This could also be used to analyze existing data in a bicycle rental application and generate a schema template based on the patterns and structure of that data. Developers could then refine and customize the schema as needed, saving time and effort compared to writing schema code from scratch.

From an end-user perspective, this client-side validation ensure the customer a good experience when combined with some like react-hook-form that prevents customers from proceeding until the required fields are filled out correctly.

Last updated