Made mongoose schemas.
This commit is contained in:
parent
d82bc75ea9
commit
6654aac896
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -120,3 +120,4 @@ dist
|
|||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
ddnet.sqlite
|
||||
.env
|
1
dotenv-template
Normal file
1
dotenv-template
Normal file
|
@ -0,0 +1 @@
|
|||
MONGO_URI = "A URI to the mongodb database."
|
7
index.js
7
index.js
|
@ -1,4 +1,9 @@
|
|||
import express from 'express'
|
||||
import databaseHandler from './libs/databaseHandler.js'
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
// Read the .env file
|
||||
dotenv.config()
|
||||
|
||||
const Server = express()
|
||||
|
||||
|
@ -12,4 +17,6 @@ Server.get('/', (req, res) =>
|
|||
)
|
||||
)
|
||||
|
||||
console.log(databaseHandler.getAllMaps("BurnyLlama"))
|
||||
|
||||
Server.listen(12345, () => console.log("Server has started!"))
|
21
libs/databaseHandler.js
Normal file
21
libs/databaseHandler.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import betterSqlite3 from 'better-sqlite3'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
const sqlite = new betterSqlite3('ddnet.sqlite', { readonly: true })
|
||||
mongoose.connect(
|
||||
process.env.MONGO_URI,
|
||||
{
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true
|
||||
},
|
||||
() => "Connected to mongodb!"
|
||||
)
|
||||
|
||||
function getAllMaps(player) {
|
||||
const stmt = sqlite.prepare('SELECT Name, Map, Time, Time, Timestamp, Server FROM race WHERE Name = ?')
|
||||
return stmt.all(player)
|
||||
}
|
||||
|
||||
export default {
|
||||
getAllMaps
|
||||
}
|
|
@ -17,6 +17,9 @@
|
|||
"author": "BurnyLlama, furo",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"express": "^4.17.1"
|
||||
"better-sqlite3": "^7.4.3",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
"mongoose": "^6.0.7"
|
||||
}
|
||||
}
|
||||
|
|
11
schemas/Finishes.js
Normal file
11
schemas/Finishes.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { Schema } from 'mongoose'
|
||||
import Level from './Level.js'
|
||||
import Player from './Player.js'
|
||||
|
||||
const Finish = new Schema({
|
||||
map: Level,
|
||||
time: Date,
|
||||
players: [Player]
|
||||
})
|
||||
|
||||
export default Finish
|
14
schemas/Level.js
Normal file
14
schemas/Level.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Schema } from 'mongoose'
|
||||
import Finish from './Finishes.js'
|
||||
|
||||
const Level = new Schema({
|
||||
name: String,
|
||||
mapper: String,
|
||||
release: Date,
|
||||
category: String,
|
||||
rating: Number,
|
||||
awardPoints: Number,
|
||||
finishes: [Finish]
|
||||
})
|
||||
|
||||
export default Level
|
13
schemas/Player.js
Normal file
13
schemas/Player.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Schema } from 'mongoose'
|
||||
import Level from './Level.js'
|
||||
|
||||
const Player = new Schema({
|
||||
name: String,
|
||||
points: Number,
|
||||
rankPoints: Number,
|
||||
teamPoints: Number,
|
||||
finishedMaps: [Level],
|
||||
favouritePartners: [Player]
|
||||
})
|
||||
|
||||
export default Player
|
Loading…
Reference in New Issue
Block a user