{"id":20578766,"url":"https://github.com/cclient/sequelize-sharding","last_synced_at":"2025-06-26T16:33:55.457Z","repository":{"id":93977626,"uuid":"158901673","full_name":"cclient/sequelize-sharding","owner":"cclient","description":"通过sequelize的hooks模块，更改读写前的table_name，实现类似spring AOP的分表读写，sequelize Model hooks for sharded-table that like [tablename]_yyyy_mm...","archived":false,"fork":false,"pushed_at":"2018-11-26T12:58:58.000Z","size":45,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T19:21:35.621Z","etag":null,"topics":["sequelize","sequelize-model-hooks","sharding"],"latest_commit_sha":null,"homepage":"https://www.cnblogs.com/zihunqingxin/p/10011710.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cclient.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-11-24T04:15:51.000Z","updated_at":"2024-01-30T07:28:36.000Z","dependencies_parsed_at":"2023-04-20T10:32:23.177Z","dependency_job_id":null,"html_url":"https://github.com/cclient/sequelize-sharding","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cclient/sequelize-sharding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cclient%2Fsequelize-sharding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cclient%2Fsequelize-sharding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cclient%2Fsequelize-sharding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cclient%2Fsequelize-sharding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cclient","download_url":"https://codeload.github.com/cclient/sequelize-sharding/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cclient%2Fsequelize-sharding/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262102619,"owners_count":23259297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sequelize","sequelize-model-hooks","sharding"],"created_at":"2024-11-16T06:14:30.355Z","updated_at":"2025-06-26T16:33:55.432Z","avatar_url":"https://github.com/cclient.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### desc\n\nsequelize Model hooks for sharded-table that like `[tablename]_yyyy_mm`...( table should be created before)\n\nuse sequelize original hooks as a \"AOP\" to change target table name\n\n`user =\u003e user_2018_01,user_2018_02, ... ,user_2018_11,user_2018_12`\n\n### start\n\n* `npm install sequelize`\n\n* `npm install git@github.com:cclient/sequelize-sharding.git` or add dependencies `sequelize-sharding\":git@github.com:cclient/sequelize-sharding.git` then `npm install`\n\n### original sequelize\n\n```js\n\nconst Sequelize = require('sequelize');\n\nconst sequelize = new Sequelize('database', 'username', 'password', {\n    host: 'localhost',\n    dialect: 'mysql',\n    pool: {\n        max: 5,\n        min: 0,\n        acquire: 30000,\n        idle: 10000\n    },\n    // SQLite only\n    storage: 'path/to/database.sqlite',\n    // http://docs.sequelizejs.com/manual/tutorial/querying.html#operators\n    operatorsAliases: false\n});\n\nconst User = sequelize.define('user', {\n    id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },\n    name: Sequelize.STRING,\n    birthday: Sequelize.DATE\n}, { freezeTableName: true, createdAt: false, updatedAt: false, deletedAt: false });\n\n\nlet user = {\n        name: \"china\",\n        birthday: new Date(\"2018-10-01\")\n    }\n\n\n```\n\n### hook\n\n#### javascript\n\n```js\n\nconst sequelizeSharding = require('sequelize-sharding');\nsequelizeSharding.useCustomTableName(sequelize, User, \"birthday\", true)\nUser.insertOrUpdate(user)\n\n```\n\n#### typescript\n\n```ts\n\nimport { useCustomTableName} from 'sequelize-sharding';\nuseCustomTableName(sequelize, User, \"birthday\", true)\nUser.insertOrUpdate(user)\n\n```\n\n### custom function to generate table's postfix like\n\n```fun\n\nuseCustomTableName(sequelize, User, null, false, function(value) {\n    return getYYMM(new Date())\n})\n\n```\n\nmore detail see test/test.js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcclient%2Fsequelize-sharding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcclient%2Fsequelize-sharding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcclient%2Fsequelize-sharding/lists"}