-
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
790d9e0
commit 81fd0ff
Showing
4 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from "https://deno.land/x/github_api@0.5.0-pre.11/mod.ts"; | ||
|
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,2 @@ | ||
export * from "https://deno.land/x/mongo@v0.31.2/mod.ts"; | ||
export { parse as parseConnectionString } from "https://deno.land/x/mongo@v0.31.2/src/utils/uri.ts"; |
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 +1,2 @@ | ||
export * from "./github/mod.ts"; | ||
export * from "./mongo/mod.ts"; |
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,46 @@ | ||
import { | ||
Database, | ||
MongoClient, | ||
parseConnectionString, | ||
} from "../../../deps/mongo.ts"; | ||
import { ILogger } from "../../mod.ts"; | ||
|
||
export class MongoService { | ||
constructor( | ||
private readonly client: MongoClient, | ||
private readonly db: Database, | ||
) { | ||
} | ||
|
||
public collection(name: string) { | ||
return this.db.collection(name); | ||
} | ||
|
||
public close() { | ||
this.client.close(); | ||
} | ||
|
||
public static async create( | ||
logging: ILogger, | ||
mongoConnectionString: string, | ||
) { | ||
if (!mongoConnectionString) { | ||
logging.warn( | ||
"mongo", | ||
"MONGO_CONNECTION_STRING not found. Please create a .env file or set up your environment correctly.", | ||
); | ||
} | ||
|
||
const client = new MongoClient(); | ||
const options = await parseConnectionString(mongoConnectionString); | ||
if (mongoConnectionString.indexOf("localhost") === -1) { | ||
options.tls = true; | ||
} | ||
const db = await client.connect(options); | ||
logging.info( | ||
`mongo`, | ||
"mongo connected", | ||
); | ||
return new MongoService(client, db); | ||
} | ||
} |