-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9266286
commit 58148b0
Showing
13 changed files
with
190 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
dist | ||
dist-test | ||
yarn.lock | ||
.env |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"loader" : "ts-node/esm", | ||
"spec": "test/**/*.test.ts", | ||
"exclude": ["node_modules"] | ||
"spec": "dist-test/**/*.test.js", | ||
"exclude": ["node_modules"], | ||
"project": "./tsconfig.test.json" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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,5 @@ | ||
import { ExampleMongoDatastore } from "../repo" | ||
|
||
export const exampleMongoDb = new ExampleMongoDatastore( | ||
"mongodb://127.0.0.1:27017/fnode" | ||
) |
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,35 @@ | ||
import mongoose, { Schema, Document } from "mongoose" | ||
import { Example } from "../types" | ||
|
||
interface ExampleDocument extends Example, Document {} | ||
|
||
const ExampleSchema = new Schema<ExampleDocument>({ | ||
boolElement: { | ||
type: Boolean, | ||
required: [true, "Please provide the boolElement"], | ||
index: { unique: true }, | ||
}, | ||
stringElement: { | ||
type: String, | ||
required: [true, "Please provide the stringElement"], | ||
}, | ||
numberElement: { | ||
type: Number, | ||
required: [true, "Please provide the numberElement"], | ||
}, | ||
objectElement: { | ||
type: Object, | ||
required: [true, "Please provide the objectElement"], | ||
}, | ||
arrayElement: { | ||
type: [Object], | ||
required: [true, "Please provide the arrayElement"], | ||
}, | ||
}) | ||
|
||
const ExampleModel = | ||
mongoose.models.Example || | ||
mongoose.model<ExampleDocument>("Example", ExampleSchema) | ||
|
||
export { ExampleModel } | ||
export type { ExampleDocument } |
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,12 @@ | ||
import { DataStore } from "../../../../src/datastore" | ||
import { MongooseDataStore } from "../../../../src/implements/mongo/datastore/MongooseDataStore" | ||
import { Example } from "../types" | ||
import { ExampleModel, ExampleDocument } from "../model" | ||
|
||
export class ExampleMongoDatastore extends DataStore<Example, ExampleDocument> { | ||
constructor(uri: string) { | ||
super( | ||
new MongooseDataStore<Example, ExampleDocument>(ExampleModel, uri) | ||
) | ||
} | ||
} |
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,11 @@ | ||
export interface Example { | ||
boolElement: boolean | ||
stringElement: string | ||
numberElement: number | ||
objectElement: { | ||
boolElement: boolean | ||
stringElement: string | ||
numberElement: number | ||
} | ||
arrayElement: Array<any> | ||
} |
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,61 @@ | ||
/******************************************************************************* | ||
* (c) 2023 unipackage | ||
* | ||
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 | ||
* (the "Apache License"). You may not use this file except in compliance with one of these | ||
* licenses. You may obtain a copy of the MIT License at | ||
* | ||
* https://opensource.org/licenses/MIT | ||
* | ||
* Or the Apache License, Version 2.0 at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the MIT License or the Apache License for the specific language governing permissions and | ||
* limitations under the respective licenses. | ||
********************************************************************************/ | ||
|
||
import assert from "assert" | ||
import { it } from "mocha" | ||
import { exampleMongoDb } from "../../helper/mongodb/instance" | ||
|
||
//@ts-ignore | ||
describe("Mongo test", () => { | ||
it("connect test", async () => { | ||
const resConnect = await exampleMongoDb.connect() | ||
assert.deepEqual(resConnect.ok, true) | ||
const resDisconnect = await exampleMongoDb.disconnect() | ||
assert.deepEqual(resDisconnect.ok, true) | ||
}) | ||
it("xx test", async () => { | ||
const resConnect = await exampleMongoDb.connect() | ||
assert.deepEqual(resConnect.ok, true) | ||
const res = await exampleMongoDb.create({ | ||
boolElement: true, | ||
numberElement: 1, | ||
stringElement: "1111", | ||
objectElement: { | ||
boolElement: false, | ||
numberElement: 2, | ||
stringElement: "111", | ||
}, | ||
arrayElement: [1, 2], | ||
}) | ||
console.log(res) | ||
assert.deepEqual(res.ok, true) | ||
const resDisconnect = await exampleMongoDb.disconnect() | ||
assert.deepEqual(resDisconnect.ok, true) | ||
}) | ||
it("yyy test", async () => { | ||
const resConnect = await exampleMongoDb.connect() | ||
assert.deepEqual(resConnect.ok, true) | ||
const res = await exampleMongoDb.find({}) | ||
console.log(res) | ||
assert.deepEqual(res.ok, true) | ||
const resDisconnect = await exampleMongoDb.disconnect() | ||
assert.deepEqual(resDisconnect.ok, true) | ||
}) | ||
}) |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist-test", | ||
"declaration": true, | ||
"target": "ES2015", | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"experimentalDecorators": true, | ||
"isolatedModules": false, | ||
"skipLibCheck": true, | ||
"jsx": "react", | ||
"incremental": false, | ||
}, | ||
"include": [ | ||
"test/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
} |