@usportslive/database-models
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

@usportslive/database-models

This package works as an ORM for a specific database scheme used in the u-sports-live ecosystem. It uses sequelize to design a series of models that communicate with the database and perform queries/mutations.

Getting Started

To install the package you can simply run:

npm install @usportslive/database-models

After that you can start using it by just importing the module

// database.js

const { initialize } = require("@usportslive/database-models");

module.exports = initialize(
  "<database-name>",
  "<user>",
  "<password>",
  {} // Options object
);
// index.js

const {
  sequelize,
  User,
  Role,
  Sport,
  Team,
  Comment
  // ...
} = require('./database.js');

sequelize.authenticate()
  .then(async () => {
    
    const user = await User.findByPk('<user-id>', {
      include: ['role', 'person']
    });

    const teams = await Team.findAnCountAll(/**/);
  });

As you can see, the package returns a sequelize (^5) instance that has all models, associations and hooks already loaded in it.

Parameter Description
db The name of the database
user The username which is used to authenticate against the database.
password The password which is used to authenticate against the database.
options An object with options (see more)

Test

Test are available although you need to have a mysql database with the credentials used in connection.spec.ts to make it work. You can run it with:

npm test

Package Sidebar

Install

npm i @usportslive/database-models

Weekly Downloads

0

Version

0.1.0

License

ISC

Unpacked Size

119 kB

Total Files

105

Last publish

Collaborators

  • gerardoagl