ionian/test.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-12-31 03:06:16 +09:00
import StreamZip, { ZipEntry } from 'node-stream-zip';
import {orderBy}from 'natural-orderby';
import {readZip,entriesByNaturalOrder} from './src/util/ziputil';
import {connectDB} from './src/database';
import { createKnexUserController } from './src/db/user';
import { createKnexContentsAccessor} from './src/db/contents';
console.log("on");
async function test_main1(){
let sz = await readZip("testdata/test_zip.zip");
let e = entriesByNaturalOrder(sz).filter(v=>v.name.split('.').pop() === "jpg");
console.log(e[0]);
console.log(e.map(v=>v.name));
}
async function test_main2(){
let db = await connectDB();
let user:{id:number}[] = await db.select('id').from('users');
console.log(user[0].id);
}
async function test_main3(){
let db = await connectDB();
let user_controller = createKnexUserController(db);
let bs = await user_controller.delUser("sss");
if(!bs) console.log("doesn't exist")
let retuser = await user_controller.createUser({username:"sss",password:"sss"});
let user = await user_controller.findUser("sss");
if(user !== undefined){
user.add("create");
console.log(user.username);
}
}
async function test_main4(){
let db = await connectDB();
const cntr = createKnexContentsAccessor(db);
await cntr.add({
title:"aaa",
basepath:"testdata",
content_type:"manga",
filename:"test_zip.zip",
additional:{comment:"aaab"},
tags:[]
});
const list = await cntr.findList();
console.log(list);
}
test_main4();