-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
61 lines (61 loc) · 1.61 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { MongoClient } from "npm:[email protected]";
import mysql from 'npm:[email protected]'
import { TakoKV } from "@takoserver/takokv";
let client;
let dbKind: undefined | string;
// deno-lint-ignore no-explicit-any
export async function connect(databaseKind: "mysql" | "mongoDB" | "denokv",username: string,password: string,addres: string,port: number,db: string): Promise<any> {
if(dbKind == undefined) {
dbKind = databaseKind
} else {
console.log("conected")
return
}
switch (databaseKind) {
case "mysql":
client = await mysqlCnecting(username,password,addres,port,db)
return "A"
case "mongoDB":
connectMongoDB().catch(console.error)
return "a"
case "denokv":
//
break
default:
console.log("databaseKind is not arrowed")
return {status: "unfaild"}
//break;
}
}
export function insert() {
}
async function mysqlCnecting(username:string, passwor: string,addres: string,port: number,db: string) {
/*
const client = await new Client().connect({
hostname: addres,
username,
db,
poolSize: 3, // connection limit
password: passwor,
});*/
client = await mysql.createConnection({
host: addres,
port: port,
user: username,
password: passwor,
database: db
})
return client
}
async function connectMongoDB(){
const uri = "mongodb+srv://<username>:<password>@<cluster-address>/test?retryWrites=true&w=majority";
const client = new MongoClient(uri);
try {
await client.connect();
console.log("Connected to the database!");
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}