-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from BuidlGuidl/feat/add-mongoose
Feat/add mongoose
- Loading branch information
Showing
12 changed files
with
220 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import mongoose from "mongoose"; | ||
|
||
declare global { | ||
// eslint-disable-next-line | ||
var mongoose: any; // This must be a `var` and not a `let / const` | ||
} | ||
|
||
// eslint-disable-next-line | ||
const MONGODB_URI = process.env.MONGODB_URI!; | ||
|
||
if (!MONGODB_URI) { | ||
throw new Error("Please define the MONGODB_URI environment variable inside .env.local"); | ||
} | ||
|
||
let cached = global.mongoose; | ||
|
||
if (!cached) { | ||
cached = global.mongoose = { conn: null, promise: null }; | ||
} | ||
|
||
async function dbConnect() { | ||
if (cached.conn) { | ||
return cached.conn; | ||
} | ||
if (!cached.promise) { | ||
const opts = { | ||
bufferCommands: false, | ||
}; | ||
cached.promise = mongoose.connect(MONGODB_URI, opts).then(mongoose => { | ||
return mongoose; | ||
}); | ||
} | ||
try { | ||
cached.conn = await cached.promise; | ||
} catch (e) { | ||
cached.promise = null; | ||
throw e; | ||
} | ||
|
||
return cached.conn; | ||
} | ||
|
||
export default dbConnect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import mongoose from "mongoose"; | ||
import { Vector } from "~~/app/types/data"; | ||
|
||
const ImpactVectorSchema = new mongoose.Schema<Vector>({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
sourceName: { | ||
type: String, | ||
required: true, | ||
}, | ||
parent: { | ||
type: String, | ||
required: true, | ||
}, | ||
fieldName: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
|
||
export default mongoose.models.ImpactVector || mongoose.model<Vector>("ImpactVector", ImpactVectorSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import mongoose from "mongoose"; | ||
import { SelectedVector, VectorList } from "~~/app/types/data"; | ||
|
||
const SelectedVectorSchema = new mongoose.Schema<SelectedVector>({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
weight: { | ||
type: Number, | ||
required: true, | ||
}, | ||
}); | ||
|
||
const VectorListSchema = new mongoose.Schema<VectorList>({ | ||
creator: { | ||
type: String, | ||
required: true, | ||
}, | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
vectors: { | ||
type: [SelectedVectorSchema], | ||
required: true, | ||
}, | ||
}); | ||
|
||
export default mongoose.models.VectorList || mongoose.model<VectorList>("VectorList", VectorListSchema); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.