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 { Plugin } from '@nocobase/server';
|
||||||
import { areas, cities, provinces } from 'china-division';
|
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
export class ChinaRegionPlugin extends Plugin {
|
export class ChinaRegionPlugin extends Plugin {
|
||||||
@ -18,6 +18,15 @@ export class ChinaRegionPlugin extends Plugin {
|
|||||||
const timer = Date.now();
|
const timer = Date.now();
|
||||||
const ChinaRegion = this.db.getModel('chinaRegions');
|
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(
|
await ChinaRegion.bulkCreate(
|
||||||
provinces.map((item) => ({
|
provinces.map((item) => ({
|
||||||
code: item.code,
|
code: item.code,
|
||||||
|
Loading…
Reference in New Issue
Block a user