Who Calls the Fleet Database
The `whocallsthefleet-database` package provides a dataset specifically structured as an embedded NeDB database for the 'Who Calls the Fleet' project (https://fleet.moe), which focuses on Kantai Collection game data. NeDB is a lightweight, embedded document-oriented database written in JavaScript, offering a subset of MongoDB's API for querying. It is designed for small-scale applications, capable of operating in-memory or persisting data to a local file. The current version of this data package is `20240308.0.1`. The original NeDB project by louischatriot is considered abandoned, with development ceasing around 2017, although forks like `@seald-io/nedb` continue active maintenance and introduce modern JavaScript features like Promises. This package's primary differentiator is its specific dataset content for 'Who Calls the Fleet', using NeDB for local, file-based storage without requiring a separate database server. It is ideal for desktop applications (Electron, nw.js) or small Node.js services requiring a local, non-concurrent data store.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'find')
cause The `Datastore` instance was not properly initialized or the database failed to load, leading to methods like `find` or `findOne` being called on an undefined object. This often happens if `autoload` is false and `loadDatabaseAsync()` wasn't called or awaited, or if the `filename` path is incorrect.fixEnsure the `filename` option points to a valid path for the NeDB data file (e.g., `path.join(__dirname, 'node_modules', 'whocallsthefleet-database', 'db.json')`) and that `autoload: true` is set, or explicitly call and `await db.loadDatabaseAsync()` before performing any operations. -
Error: Could not load database, it was already loaded.
cause Attempting to call `loadDatabaseAsync()` or rely on `autoload: true` on a `Datastore` instance that has already loaded its data.fixAvoid calling `loadDatabaseAsync()` multiple times. If `autoload: true` is used in the constructor, the database loads once, and subsequent calls are unnecessary. For programmatic control, initialize the `Datastore` once and then use its methods without re-loading. -
Error: unique constraint violated
cause Attempting to insert a document with a value for an indexed field that has a unique constraint, where that value already exists in another document.fixBefore inserting, check if a document with the conflicting unique field value already exists. Alternatively, handle the error gracefully or remove the unique constraint if it's not strictly required for your data model. Ensure your `ensureIndexAsync` calls correctly define unique constraints.
Warnings
- breaking The GitHub repository for `whocallsthefleet-database` (TeamFleet/WhoCallsTheFleet-DB) was archived by the owner on December 20, 2024, and is now read-only. This indicates that the package providing this dataset is no longer actively maintained or developed. While data updates might still occur, the distribution method via this package or its source code will not receive further changes or bug fixes.
- gotcha The underlying NeDB project (louischatriot/nedb) is considered abandoned, with no new features or active maintenance since 2017. While it remains functional for basic use cases, users are strongly encouraged to use actively maintained forks like `@seald-io/nedb` for better stability, modern API features (Promises), and ongoing bug fixes.
- gotcha NeDB is an embedded database designed for small datasets and primarily operates in-memory for performance. While it supports persistence to a file, it does not offer robust concurrency control or support for multi-process environments. Each process will have its own copy of the database, making data synchronization complex and prone to issues.
- gotcha NeDB uses an append-only file format for persistence, which can lead to larger file sizes over time. Automatic compaction occurs upon database loading, but manual compaction might be necessary for specific performance or storage requirements.
Install
-
npm install whocallsthefleet-database -
yarn add whocallsthefleet-database -
pnpm add whocallsthefleet-database
Imports
- Datastore
const Datastore = require('nedb');import Datastore from 'nedb'; // or '@seald-io/nedb'
- Datastore (with path)
import { db } from 'whocallsthefleet-database';import Datastore from '@seald-io/nedb'; const db = new Datastore({ filename: './node_modules/whocallsthefleet-database/db.json', autoload: true }); - Promise API
db.loadDatabase(() => { /* callback style */ });import Datastore from '@seald-io/nedb'; const db = new Datastore({ filename: './node_modules/whocallsthefleet-database/db.json' }); await db.loadDatabaseAsync(); // Using the async/Promise API from @seald-io/nedb
Quickstart
import Datastore from '@seald-io/nedb'; // Use @seald-io/nedb for modern Promise API
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Determine the path to the database file provided by whocallsthefleet-database
// This path assumes 'whocallsthefleet-database' is installed in node_modules
const dbPath = path.join(__dirname, 'node_modules', 'whocallsthefleet-database', 'db.json');
async function loadAndQueryData() {
try {
// Initialize a new Datastore instance, pointing to the data file
const db = new Datastore({
filename: dbPath,
autoload: true // Automatically load the database on creation
});
// Wait for the database to be loaded (autoload handles this implicitly, but explicit wait is good practice for persistence setup)
// If not using autoload, you would call await db.loadDatabaseAsync();
console.log('Database loaded from:', dbPath);
// Example: Find all documents in the database
const allDocs = await db.findAsync({});
console.log(`Found ${allDocs.length} documents.`);
// Example: Find documents matching a specific criteria (e.g., a 'name' field, assuming data structure)
// Note: The actual fields depend on the 'Who Calls the Fleet' data schema.
// This is a placeholder example.
const exampleDoc = await db.findOneAsync({ 'id': 'some_kancolle_id' }); // Replace with actual query
if (exampleDoc) {
console.log('Example document found:', exampleDoc);
} else {
console.log('No document found with example ID.');
}
// You can also count documents
const count = await db.countAsync({});
console.log(`Total documents (counted): ${count}`);
} catch (error) {
console.error('Error interacting with the database:', error);
}
}
loadAndQueryData();