Constructor
new CouchDbNoteRepository(url, dbName) → {CouchDbNoteRepository}
Create a new CouchDbNoteRepository
Parameters:
Name | Type | Description |
---|---|---|
url |
string | CouchDB connection URL (including authentication if required) |
dbName |
string | Database name to use for storing notes |
- Source:
Returns:
New CouchDbNoteRepository instance
Example
const repository = new CouchDbNoteRepository('http://admin:password@localhost:5984', 'notes_db');
await repository.init();
const notes = await repository.findAll();
Extends
Classes
Methods
(async) countDeleted() → {Promise.<number>}
Count the number of deleted notes in recycle bin
- Overrides:
- Source:
Throws:
-
When database query fails or CouchDB is unreachable
- Type
- Error
Returns:
Promise resolving to the count of deleted notes
- Type
- Promise.<number>
Example
const count = await repository.countDeleted();
console.log(`Recycle bin contains ${count} notes`);
(async) create(note) → {Promise.<Note>}
Create a new note in the database
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
note |
Object | The note data to create Properties
|
- Overrides:
- Source:
Throws:
-
When note creation fails or database is unreachable
- Type
- Error
Returns:
Promise resolving to the created Note object with assigned ID
- Type
- Promise.<Note>
Example
const newNote = await repository.create({
title: 'My New Note',
content: 'This is the content of my note'
});
console.log(`Created note with ID: ${newNote.id}`);
(async) emptyRecycleBin() → {Promise.<number>}
Empty the recycle bin by permanently deleting all deleted notes
- Overrides:
- Source:
Throws:
-
When operation fails due to database issues
- Type
- Error
Returns:
Promise resolving to the number of notes permanently deleted
- Type
- Promise.<number>
Example
const deletedCount = await repository.emptyRecycleBin();
console.log(`Permanently deleted ${deletedCount} notes from recycle bin`);
(async) findAll() → {Promise.<Array.<Note>>}
Find all active notes (not deleted)
- Overrides:
- Source:
Throws:
-
When database query fails or CouchDB is unreachable
- Type
- Error
Returns:
Promise resolving to an array of active Note objects
- Type
- Promise.<Array.<Note>>
Example
const activeNotes = await repository.findAll();
console.log(`Found ${activeNotes.length} active notes`);
(async) findAllIncludingDeleted() → {Promise.<Array.<Note>>}
Find all notes regardless of deletion status
- Overrides:
- Source:
Throws:
-
When database query fails or CouchDB is unreachable
- Type
- Error
Returns:
Promise resolving to an array of all Note objects
- Type
- Promise.<Array.<Note>>
(async) findById(id) → {Promise.<(Note|null)>}
Find a note by its unique identifier
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The unique ID of the note to retrieve |
- Overrides:
- Source:
Throws:
-
When database query fails (except for 404 not found)
- Type
- Error
Returns:
Promise resolving to a Note object or null if not found
- Type
- Promise.<(Note|null)>
Example
const note = await repository.findById('note_123');
if (note) {
console.log(`Found note: ${note.title}`);
} else {
console.log('Note not found');
}
(async) findDeleted() → {Promise.<Array.<Note>>}
Find all deleted notes (in recycle bin)
- Overrides:
- Source:
Throws:
-
When database query fails or CouchDB is unreachable
- Type
- Error
Returns:
Promise resolving to an array of deleted Note objects
- Type
- Promise.<Array.<Note>>
Example
const deletedNotes = await repository.findDeleted();
console.log(`Found ${deletedNotes.length} notes in recycle bin`);
(async) init() → {Promise.<void>}
Initialize the repository by ensuring the database exists and creating necessary design documents. This method must be called before using any other repository methods.
- Source:
Throws:
-
-
When CouchDB is unreachable or database creation fails
- Type
- Error
-
-
-
When design document creation fails
- Type
- Error
-
Returns:
- Type
- Promise.<void>
Example
const repository = new CouchDbNoteRepository(url, dbName);
await repository.init(); // Creates database and design documents if needed
(async) moveToRecycleBin(id) → {Promise.<boolean>}
Move a note to recycle bin (soft delete)
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the note to move to recycle bin |
- Overrides:
- Source:
Throws:
-
When operation fails due to database issues
- Type
- Error
Returns:
Promise resolving to true if moved to recycle bin, false if not found
- Type
- Promise.<boolean>
Example
const moved = await repository.moveToRecycleBin('note_123');
if (moved) {
console.log('Note moved to recycle bin successfully');
} else {
console.log('Note not found');
}
(async) permanentDelete(id) → {Promise.<boolean>}
Permanently delete a note from the database
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the note to permanently delete |
- Overrides:
- Source:
Throws:
-
When deletion fails due to database issues
- Type
- Error
Returns:
Promise resolving to true if deleted, false if not found
- Type
- Promise.<boolean>
Example
const deleted = await repository.permanentDelete('note_123');
if (deleted) {
console.log('Note permanently deleted');
} else {
console.log('Note not found');
}
(async) restore(id) → {Promise.<boolean>}
Restore a note from recycle bin
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the note to restore |
- Overrides:
- Source:
Throws:
-
When operation fails due to database issues
- Type
- Error
Returns:
Promise resolving to true if restored, false if not found
- Type
- Promise.<boolean>
Example
const restored = await repository.restore('note_123');
if (restored) {
console.log('Note restored successfully');
} else {
console.log('Note not found');
}
(async) restoreAll() → {Promise.<number>}
Restore all notes from recycle bin
- Overrides:
- Source:
Throws:
-
When operation fails due to database issues
- Type
- Error
Returns:
Promise resolving to the number of notes restored
- Type
- Promise.<number>
Example
const restoredCount = await repository.restoreAll();
console.log(`Restored ${restoredCount} notes from recycle bin`);
(async) update(id, note) → {Promise.<(Note|null)>}
Update an existing note in the database
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | The ID of the note to update |
|||||||||
note |
Object | The updated note data Properties
|
- Overrides:
- Source:
Throws:
-
-
When update fails due to database issues
- Type
- Error
-
-
-
When document was modified concurrently (409 conflict)
- Type
- Error
-
Returns:
Promise resolving to the updated Note object or null if not found
- Type
- Promise.<(Note|null)>
Example
const updatedNote = await repository.update('note_123', {
title: 'Updated Title',
content: 'Updated content'
});
if (updatedNote) {
console.log('Note updated successfully');
} else {
console.log('Note not found');
}