Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Files

Latest commit

 

History

History
20 lines (14 loc) · 1.58 KB

FileDataStore.md

File metadata and controls

20 lines (14 loc) · 1.58 KB

The FileDataStore class

This data store persists its data to JSON files, which means the data doesn't go away when your app restarts, like it does with the MemoryDataStore. This allows you to easily create an API that acts like it has a real database behind it, so you can use the Mock middleware to create some data, and then use that data for a demos and presentations days or weeks later.

NOTE: The FileDataStore is not intended to replace a full-featured database. It does not provide features such as fault-tolerance, transactions, concurrency, etc. However, you can easily integrate with a full-featured database system (such as MySQL, SqlLite, Oracle, etc.) by creating your own class that inherits from the DataStore base class. You simply need to override the __openDataStore and __saveDataStore methods. See the FileDataStore source code for an example.

Constructor

FileDataStore(baseDir)

  • baseDir (optional) - string
    The directory where the JSON files will be saved. The FileDataStore will create separate folders and files under this directory for each path in your Swagger API.

    If you don't specify this parameter, then it defaults to process.cwd().

Methods

The FileDataStore class inherits from the DataStore class, so it has all the same methods for retrieving, saving, and deleting data.