agrs-sequelize-sdk
v1.3.60
Published
The `agrs-sequelize` SDK provides a structured way to manage your database models using Sequelize ORM. It allows you to easily add, update, and manage models, with support for publishing updates to NPM and pushing changes to GitHub.
Downloads
3,900
Readme
agrs-sequelize SDK
The agrs-sequelize SDK provides a structured way to manage your database models using Sequelize ORM. It allows you to easily add, update, and manage models, with support for publishing updates to NPM and pushing changes to GitHub.
Table of Contents
- Prerequisites
- Installation
- Usage
- Publishing Changes
- Script Details
- Example Model File
- Versioning
- Troubleshooting
- License
Prerequisites
Ensure the following dependencies are installed on your system:
- Node.js: Download Node.js
- Sequelize: Used for database interaction.
- Git: Required for version control and publishing changes to GitHub.
- npm: For managing and publishing packages.
- PowerShell (Windows) or Bash (Linux/macOS): For running automation scripts.
Installation
Clone the Repository:
git clone https://github.com/your-repo/agrs-sequelize.git cd agrs-sequelizeInstall Dependencies:
npm install
Usage
Adding or Modifying Models
To add or modify models in the agrs-sequelize SDK:
Create or Edit a Model:
- Add a new model file inside the models directory or edit an existing one.
- Each model file should export a function that initializes the model with Sequelize.
// models/YourModel.js
module.exports = (sequelize, DataTypes) => {
const YourModel = sequelize.define('YourModel', {
fieldName: {
type: DataTypes.STRING,
allowNull: false,
},
});
// Define associations (optional)
YourModel.associate = (models) => {
YourModel.hasMany(models.OtherModel);
};
return YourModel;
}; Define Associations (if required):
Use the associate method to define relationships with other models. Associations like hasMany, belongsTo, etc., are supported.
Model Loading
Models are automatically loaded when initializing Sequelize.
The index.js file ensures all models in the models directory are properly loaded and associated.Publishing Changes
After modifying or adding models, publish the changes to NPM and GitHub.
Using PowerShell (Windows)
Open PowerShell as Administrator.
Run the Script:
./run.ps1The script will:
- Check for jq installation.
- Bump the version in package.json.
- Publish to NPM.
- Commit and push changes to GitHub.
Using Bash (Linux/macOS)
Open a Bash Terminal.
Run the Script:
./run.shThe script performs the same tasks as the PowerShell script, tailored for Bash environments.
Script Details
run.ps1 (PowerShell Script for Windows)
Automates the publishing process:
- Ensures jq is installed.
- Increments the version in package.json.
- Publishes the package to NPM.
- Commits and pushes changes to GitHub.
run.sh (Bash Script for Linux/macOS)
Provides similar functionality:
- Checks for jq installation.
- Bumps the package version. = Publishes to NPM. = Commits and pushes to GitHub.
Example Model File
Copy code
// models/YourModel.js
module.exports = (sequelize, DataTypes) => {
const YourModel = sequelize.define('YourModel', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
});
// Define associations (optional)
YourModel.associate = (models) => {
YourModel.hasMany(models.OtherModel);
};
return YourModel;
};In this example:
YourModel has a name field. It has a hasMany association with OtherModel.
Versioning
Versioning is handled automatically:
- The scripts increment the version in package.json.
- Follows semantic versioning (major, minor, patch).
- Updated versions are published to NPM and committed to the repository.
Troubleshooting
Permission Issues:
- Linux/macOS: Ensure scripts have execute permissions (chmod +x run.sh).
NPM Login Errors:
- The script will prompt for NPM login if not already logged in.
- Verify NPM account credentials.
Missing Dependencies:
- The script checks for jq and installs it if missing.
License
This project is licensed under the MIT License. See the LICENSE file for details.
