Skip to content

Commit

Permalink
0.5.0-pre.15
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmchase committed Aug 8, 2023
1 parent 790d9e0 commit 81fd0ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
1 change: 0 additions & 1 deletion deps/github.ts
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";

2 changes: 2 additions & 0 deletions deps/mongo.ts
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";
1 change: 1 addition & 0 deletions src/services/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./github/mod.ts";
export * from "./mongo/mod.ts";
46 changes: 46 additions & 0 deletions src/services/mongo/mod.ts
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);
}
}

0 comments on commit 81fd0ff

Please sign in to comment.