mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:38:51 +00:00
feat(plugin-china-region): import data with sqlite
This commit is contained in:
parent
219dbee467
commit
3fb66d345f
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user