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.
npm install agrs-sequelize-sdkagrs-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.
bash
git clone https://github.com/your-repo/agrs-sequelize.git
cd agrs-sequelize
`
2. Install Dependencies:
`bash
npm install
`
Usage
Adding or Modifying Models
To add or modify models in the agrs-sequelize SDK:
1. 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.
`javascript
// 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;
};
`
2. Define Associations (if required):
Use the associate method to define relationships with other models.
Associations like hasMany, belongsTo, etc., are supported.
$3
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.
$3
Open PowerShell as Administrator.
Run the Script:
`powershell
./run.ps1
`
The script will:
- Check for jq installation.
- Bump the version in package.json.
- Publish to NPM.
- Commit and push changes to GitHub.
$3
Open a Bash Terminal.
Run the Script:
`bash
./run.sh
`
The script performs the same tasks as the PowerShell script, tailored for Bash environments.
Script Details
$3
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.
$3
Provides similar functionality:
- Checks for jq installation.
- Bumps the package version.
= Publishes to NPM.
= Commits and pushes to GitHub.
Example Model File
`javascript
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;
};
``