app moved to next.js
This commit is contained in:
1 parent
dcca513aea
commit
43af2996bf
48 files changed
+1147
-1027
No files matched your search
+12
-6
@@ -1,13 +1,19 @@
|
||||
const db = require('./db')
|
||||
|
||||
const store = new Map()
|
||||
|
||||
class Data {
|
||||
static setStore(Class, collection) {
|
||||
store.set(Class, collection)
|
||||
}
|
||||
static setStore(Class, collection) {
|
||||
store.set(Class, collection)
|
||||
}
|
||||
|
||||
static getStore(Class) {
|
||||
return store.get(Class)
|
||||
}
|
||||
static getStore(Class) {
|
||||
return store.get(Class)
|
||||
}
|
||||
|
||||
static getCollection(name) {
|
||||
return db.collection(name)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Data
|
||||
+28
-23
@@ -7,37 +7,42 @@ const Document = require('./Document')
|
||||
const Image = require('./Image')
|
||||
const Settings = require('./Config')
|
||||
|
||||
const {MongoClient, ObjectId} = require('mongodb')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
export var db
|
||||
var db
|
||||
|
||||
export async function connect(uri) {
|
||||
const c = await MongoClient.connect(uri)
|
||||
db = init(c)
|
||||
return db
|
||||
async function connect(uri) {
|
||||
const connection = await MongoClient.connect(uri)
|
||||
db = init(connection)
|
||||
return db
|
||||
}
|
||||
|
||||
export function collection(name) {
|
||||
return db.collection(name)
|
||||
function collection(name) {
|
||||
return db.collection(name)
|
||||
}
|
||||
|
||||
export const c = collection
|
||||
|
||||
export function id(i) {
|
||||
if (typeof i === 'string') return ObjectId(i)
|
||||
else if (i instanceof ObjectId) return i
|
||||
else if (i instanceof Object) return '_id' in i ? ObjectId(i._id) : null
|
||||
return null
|
||||
function id(i) {
|
||||
if (typeof i === 'string') return ObjectId(i)
|
||||
else if (i instanceof ObjectId) return i
|
||||
else if (i instanceof Object) return '_id' in i ? ObjectId(i._id) : null
|
||||
return null
|
||||
}
|
||||
|
||||
function init(db) {
|
||||
Data.setStore(Page, db.collection('pages'))
|
||||
Data.setStore(Article, db.collection('articles'))
|
||||
Data.setStore(Album, db.collection('albums'))
|
||||
Data.setStore(Image, db.collection('images'))
|
||||
Data.setStore(Teacher, db.collection('collective'))
|
||||
Data.setStore(Document, db.collection('documents'))
|
||||
Data.setStore(Settings, db.collection('settings'))
|
||||
// Data.setStore('Page', db.collection('pages'))
|
||||
Data.setStore(Page, db.collection('pages'))
|
||||
Data.setStore(Article, db.collection('articles'))
|
||||
Data.setStore(Album, db.collection('albums'))
|
||||
Data.setStore(Image, db.collection('images'))
|
||||
Data.setStore(Teacher, db.collection('collective'))
|
||||
Data.setStore(Document, db.collection('documents'))
|
||||
Data.setStore(Settings, db.collection('settings'))
|
||||
|
||||
return db
|
||||
return db
|
||||
}
|
||||
|
||||
exports.getDb = () => db
|
||||
exports.connect = connect
|
||||
exports.collection = collection
|
||||
exports.c = collection
|
||||
exports.id = id
|
||||
Reference in new issue
Block a user