diff --git a/packages/plugins/china-region/src/server.ts b/packages/plugins/china-region/src/server.ts index 7a95837c7c..367c980377 100644 --- a/packages/plugins/china-region/src/server.ts +++ b/packages/plugins/china-region/src/server.ts @@ -1,5 +1,5 @@ +import { Database } from '@nocobase/database'; import { Plugin } from '@nocobase/server'; -import { areas, cities, provinces } from 'china-division'; import { resolve } from 'path'; export class ChinaRegionPlugin extends Plugin { @@ -18,6 +18,15 @@ export class ChinaRegionPlugin extends Plugin { const timer = Date.now(); const ChinaRegion = this.db.getModel('chinaRegions'); + const db = new Database({ + dialect: 'sqlite', + storage: resolve(process.cwd(), 'node_modules/china-division/dist/data.sqlite'), + }); + + const [provinces] = await db.sequelize.query('SELECT `code`, `name` FROM `province`') as any; + const [cities] = await db.sequelize.query('SELECT `code`, `name`, `provinceCode` FROM `city`') as any; + const [areas] = await db.sequelize.query('SELECT `code`, `name`, `cityCode` FROM `area`') as any; + await ChinaRegion.bulkCreate( provinces.map((item) => ({ code: item.code,