# Schemas

## Summary

By employing prompt stores in generative AI, developers can maintain context regarding specific libraries or configurations, such as "bicycle-app-config," to streamline the process of generating consistent schema records in databases. This approach enhances code maintainability, readability, and reduces the likelihood of errors when accessing data.

## Example: Creating an Object Schema in MongoDB using ChatGPT

A developer wants to create consistent schema records for their MongoDB database while utilizing the "bicycle-app-config" context. They can provide a template prompt to the generative AI model like ChatGPT, which outlines the desired structure and standard fields for the schema.

### Prompt:

{% code title="prompt" overflow="wrap" %}

```
Generate a MongoDB schema definition using Mongoose that includes the following standard fields: id, createdDate, lastModifiedDate, createdBy, and lastModifiedBy. The schema should automatically handle the createdDate and lastModifiedDate fields. Consider the bicycle-app-config context.
```

{% endcode %}

### Response:

{% code overflow="wrap" %}

```javascript
const mongoose = require('mongoose');
const { Schema } = mongoose;

const BaseSchema = new Schema(
  {
    _id: {
      type: Schema.Types.ObjectId,
      auto: true,
    },
    createdDate: {
      type: Date,
      default: Date.now,
    },
    lastModifiedDate: {
      type: Date,
      default: Date.now,
    },
    createdBy: {
      type: String,
      required: true,
    },
    lastModifiedBy: {
      type: String,
      required: true,
    },
  },
  {
    timestamps: {
      createdAt: 'createdDate',
      updatedAt: 'lastModifiedDate',
    },
  }
);

module.exports = BaseSchema;
```

{% endcode %}

### Discussion

Utilizing prompt stores in generative AI can enhance the development process and bring unity and standardization to the output:

#### Pros:

1. Streamlines the process of generating code by maintaining context and reducing redundancy.
2. Enhances code maintainability and readability by ensuring consistency.
3. Reduces the likelihood of errors when accessing data.

#### Cons:

1. Requires careful management of the prompt store context to avoid confusion or unintended consequences.
