Skip to content

Commit

Permalink
Merge pull request #14 from kne-union/linzp
Browse files Browse the repository at this point in the history
修改到esm
  • Loading branch information
zhipenglin authored Dec 9, 2024
2 parents 893e93b + 184cf7a commit 1cefa91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const fp = require('fastify-plugin');
const Sequelize = require('sequelize');
const fs = require('fs');
const path = require('path');
const { glob } = require('glob');
const merge = require('lodash/merge');
const camelCase = require('lodash/camelCase');
const snakeCase = require('lodash/snakeCase');
const { Snowflake } = require('nodejs-snowflake');
import fp from 'fastify-plugin';
import { Sequelize, DataTypes } from 'sequelize';
import fs from 'node:fs';
import path from 'node:path';
import { glob } from 'glob';
import { merge, camelCase, snakeCase } from 'lodash-es';
import { Snowflake } from 'nodejs-snowflake';

const defaultConfig = {
db: {
Expand All @@ -25,7 +23,7 @@ const defaultConfig = {
name: 'models'
};

module.exports = fp(
const sequelize = fp(
async (fastify, options) => {
const config = merge({}, defaultConfig, options);
const { getUniqueID } = new Snowflake(config.snowflake);
Expand All @@ -49,7 +47,7 @@ module.exports = fp(
const registerDB = (module, targetName) => {
const { name, model, associate, options } = module({
sequelize,
DataTypes: Sequelize.DataTypes,
DataTypes,
fastify,
options: config
});
Expand All @@ -64,7 +62,7 @@ module.exports = fp(
{},
{
id: {
type: Sequelize.DataTypes.BIGINT.UNSIGNED,
type: DataTypes.BIGINT.UNSIGNED,
primaryKey: true,
set() {
return getUniqueID();
Expand Down Expand Up @@ -129,3 +127,5 @@ module.exports = fp(
name: 'fastify-sequelize'
}
);

export default sequelize;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kne/fastify-sequelize",
"version": "3.0.0-alpha.1",
"version": "3.0.0-alpha.2",
"description": "用于封装sequelize调用",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -38,10 +38,10 @@
"sqlite3": "^5.1.7"
},
"dependencies": {
"fastify-plugin": "^4.5.1",
"glob": "^10.3.15",
"lodash": "^4.17.21",
"fastify-plugin": "^5.0.1",
"glob": "^11.0.0",
"lodash-es": "^4.17.21",
"nodejs-snowflake": "^2.0.1",
"sequelize": "^6.37.3"
"sequelize": "^6.37.5"
}
}

0 comments on commit 1cefa91

Please sign in to comment.