-
Notifications
You must be signed in to change notification settings - Fork 7
/
makeStore.ts
42 lines (41 loc) · 1.43 KB
/
makeStore.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
import { CookieStore, MemoryStore, PostgresStore, RedisStore, SqliteStore, MongoStore, Store, WebdisStore } from "../mod.ts";
import { connect as connectRedis } from "https://deno.land/x/redis@v0.25.5/mod.ts"
import { DB as sqliteDB } from "https://deno.land/x/sqlite@v3.4.0/mod.ts"
import { MongoClient } from "https://deno.land/x/mongo@v0.29.4/mod.ts";
import postgres from "https://deno.land/x/postgresjs@v3.1.0/mod.js"
export async function makeStore(): Promise<Store | CookieStore> {
switch(Deno.env.get('STORE')) {
case 'cookie':
return new CookieStore('mandatory-encryption-passphrase')
case 'sqlite':
const sqlite = new sqliteDB('./database.db')
return new SqliteStore(sqlite)
case 'redis':
const redis = await connectRedis({
hostname: '0.0.0.0',
port: 6379
})
return new RedisStore(redis)
case 'webdis':
return new WebdisStore({
url: 'http://127.0.0.1:7379'
})
case 'postgres':
const sql = postgres({
host: 'localhost',
port: 26257,
database: 'defaultdb',
user: 'root',
password: '',
})
const store = new PostgresStore(sql)
await store.initSessionsTable()
return store
case 'mongo':
const client = new MongoClient()
const mongo = await client.connect("mongodb://localhost:27017")
return new MongoStore(mongo)
default:
return new MemoryStore()
}
}