飞道科技

飞道科技文档总汇

数据库插入多条数据

import { v4 as uuid } from 'uuid';
import insert from './atom/db/insert';

import { IBaseTable } from './atom/db/interfaces';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
    names: string[];
}

interface Student extends IBaseTable {
    name: string;
}

async function atom(msg: Message) {
    const { exec, prepare } = insert(action_id, session_id, spaceid, '1000');
    const data = msg.names.map((name)=>{
        return {
            _id: uuid(),
            name
        };
    });
    prepare<Student>('student', data);
    const ret = await exec();
    if (ret.code === 1) {
        return 'success';
    } else {
        return 'fail';
    }
}