Database Packages
This guide outlines best practices for creating packages that manage data storage in the monorepo.
Data Storage Location
Packages that manage data (such as SQLite databases, session storage, etc.) should:
- Store their data in a
data/
directory within the package - Handle the data path internally by default rather than requiring it to be passed in
- Create the
data/
directory if it doesn't exist - Add
data/
to.gitignore
to prevent committing data files
Example structure:
package-name/
├── package.json
├── src/
│ └── index.ts
└── data/ # Data storage directory
└── .gitkeep # To ensure directory exists in git
Testing Behavior
When NODE_ENV
is set to "test":
- Use in-memory storage by default
- Each test should start with a fresh state
- No data should be persisted to disk
Example implementation:
typescript
export class Database {
private db: DatabaseImpl;
constructor() {
if (process.env.NODE_ENV === "test") {
this.db = new InMemoryDatabase();
} else {
this.db = new SQLiteDatabase("./data/database.sqlite");
}
}
}