1.0.6 • Published 6 months ago

@pikmeup/database-service v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

@pikmeup/database-service

A shared database service for PikMeUp microservices using Typegoose with MongoDB.

Installation

npm install @pikmeup/database-service

Usage

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 management
  • Driver - Driver information
  • Cab - Cab details
  • Route - Route information
  • Trip - 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 build

License

MIT

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago