@medomino-170/utils
v0.0.48
Published
> build 文件夹是生成好的 js 文件和 .d.ts
Downloads
16
Readme
medo-ts2
build 文件夹是生成好的 js 文件和 .d.ts
crypto-js 3.3.0 最新版(4.x)打包体积过大
how to use
数组相关方法
byte-conversion
import { byteConversion } from "../../ts/byte-conversion";
console.log(byteConversion(1000))
deepcopy
import { deepCopy, deepProxy } from "../../src/deepcopy";
import { Logger } from "../../src/logjs-extend";
const a = { a: 1 };
Object.freeze(a)
const max = 1e5;
const logger = new Logger();
for (let i = 0; i < max; i++) {
// const b = deepCopy(a)
// b.a = 123
const b = deepProxy(a, (a) => {
a.a = 123;
});
}
logger.log("done");
mongo
import { mongoConfigs } from "../../../../private/medomino/build/datebase/index";
import { Mongo } from "../../ts/mongo";
const mongoConfig = {
url: `${mongoConfigs.url}/medo_mango?authSource=admin`,
option: {
useUnifiedTopology: true,
useNewUrlParser: true,
minPoolSize: 2,
maxPoolSize: 100,
},
};
const mgsql = new Mongo(mongoConfig);
async function init() {
for (let i = 0; i < 100; i++) {
await mgsql.find({
table: "std_doctor",
query: {},
limit: 1,
});
}
// const data = await mgsql.find({
// table: "std_doctor",
// query: {},
// limit: 1,
// });
process.exit();
}
init();
mysql
import { Mysql } from "../../ts/mysql/index";
import { mysqlConf } from "../../configs/index";
import { Logger } from "../../ts/logjs-extend";
const mysql = new Mysql(mysqlConf);
async function init() {
const table = "nlp_entity";
const limit = 1e5;
const db = "new_beigene_demo_2021";
// const ids: { id: string }[] = await mysql.query(
// `select id from ?? where type = '疾病' and value = '肿瘤'`,
// [table],
// db
// );
// const id = ids.map((x) => x.id);
// console.log(ids.length);
// const logger = new Logger();
// // const data = await mysql.query(`select id from ?? where id in (?)`, [table, id], db)
// const extend =
// `SELECT ? AS id UNION ALL ` +
// Array(id.length - 1)
// .fill(`SELECT ?`)
// .join(" UNION ALL ");
// const params = id;
// console.log(`SELECT id from (${extend}) AS a LEFT JOIN ?? AS b ON a.id = b.id`)
// console.log(params.concat([table]))
// const data = await mysql.query(
// `SELECT a.id from (${extend}) AS a LEFT JOIN ?? AS b ON a.id = b.id where b.id is not null`,
// params.concat([table]),
// db
// );
// const data = await mysql.query(
// `SELECT a.id from ?? as a inner join (${extend}) AS b ON a.id = b.id `,
// [table].concat(params),
// db
// );
// const data = await mysql.joinIn({
// table,
// ids: id,
// key: "id",
// fields: ["id"],
// db,
// custom: 'distinct a.rid'
// });
// console.log(data.length)
// logger.log("done");
// const data = await mysql.query(`show databases`, [table]);
const data = await mysql.query(`select * from ?? limit 10`, [table], db);
// const data = await mysql.joinIn({
// table,
// ids: ["000004ffaa584902eaa33421d4073137"],
// key: "id",
// fields: ["id"],
// // db,
// custom: "distinct a.rid",
// });
console.log(data);
// process.exit();
}
init();
postgresql
import { PostgreSql } from "../../src/postgresql";
import { Logger } from "../../src/logjs-extend";
import { fse, path } from "../../src/fse";
import { pgsqlConfigs } from "../../../../private/medomino/build/datebase";
const pgsql = new PostgreSql({
host: pgsqlConfigs.host,
port: pgsqlConfigs.port,
user: pgsqlConfigs.username,
password: pgsqlConfigs.password,
database: "medo_master",
});
async function init() {
// const data = await pgsql.query(`select rid from ask_normalization limit ?`, [
// 1e4
// ]);
// await fse.writeJSON(path.join(__dirname, '1.json'), data)
let data: any[] = await fse.readJSON(path.join(__dirname, "1.json"));
data = data.concat(data);
// data = data.concat(data)
// data = data.concat(data)
// data = data.concat(data)
// data = data.concat(data)
console.log(data.length);
const logger = new Logger();
// SELECT regexp_split_to_table(?, ',' ) AS id
// const res = await pgsql.query(`select rid from ask_normalization where rid in (?)`, [data.map(x => x.rid)])
// const res = await pgsql.query(`select rid from ask_normalization where rid in (SELECT regexp_split_to_table(?, ',' ) AS id)`, [data.map(x => x.rid).join()])
// const res = await pgsql.query(`SELECT regexp_split_to_table(?, ',' ) AS id`, [data.map(x => x.rid).join()])
const res = await pgsql.query(
`SELECT rid FROM ask_normalization WHERE EXISTS (SELECT 1 FROM (SELECT regexp_split_to_table(?, ',' ) AS id) as a WHERE a.id = ask_normalization.rid);`,
[data.map((x) => x.rid).join()]
);
// for (let i = 0; i < 1; i++) {
// const res = await pgsql.joinIn({
// table: "ask_normalization",
// key: "rid",
// ids: data.map((x) => x.rid),
// fields: ["rid"],
// });
// console.log(res.length, 'res')
// // const res = await pgsql.query(
// // `SELECT regexp_split_to_table(?, ',' ) AS id`,
// // [data.map(x => x.rid).join()]
// // );
// logger.log(`${i + 1} / ${10}`);
// }
logger.log("done");
process.exit();
}
init();
typescript 相关基础方法
import { MedoTypes, MedoTypesM } from "../../ts/types";
console.log(MedoTypesM.getKeys);
type d = MedoTypes.GetKeys<{}>;