1.0.6 • Published 6 months ago
@pikmeup/database-service v1.0.6
@pikmeup/database-service
A shared database service for PikMeUp microservices using Typegoose with MongoDB.
Installation
npm install @pikmeup/database-serviceUsage
Basic Setup
import { connectToDatabase, disconnectFromDatabase, models } from '@pikmeup/database-service';
// Connect to MongoDB
await connectToDatabase('mongodb://localhost:27017/your-database');
// Use models
const user = await models.User.create({
name: 'John Doe',
email: 'john@example.com',
password: 'securepassword',
role: 'employee'
});
// Disconnect when done
await disconnectFromDatabase();Available Models
User- User managementDriver- Driver informationCab- Cab detailsRoute- Route informationTrip- Trip records
Example: Creating a Driver with User
import { models, Role } from '@pikmeup/database-service';
// First create a user
const user = await models.User.create({
name: 'Driver Name',
email: 'driver@example.com',
password: 'securepassword',
role: Role.DRIVER
});
// Then create the driver profile
const driver = await models.Driver.create({
name: 'Driver Name',
email: 'driver@example.com',
phone: '1234567890',
licenseNumber: 'DL123456',
status: 'AVAILABLE',
userId: user._id
});Example: Creating a Cab with Driver
const cab = await models.Cab.create({
number: 'KA01AB1234',
capacity: 4,
driver: driver._id
});Configuration
The package uses Typegoose with MongoDB. Make sure your MongoDB instance is running and accessible.
Development
# Install dependencies
npm install
# Run tests
npm test
# Build the package
npm run buildLicense
MIT