This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
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.
Merge pull request #2 from burhanahmeed/dev.0.1
Dev.0.1
- Loading branch information
Showing
13 changed files
with
137 additions
and
28 deletions.
There are no files selected for viewing
Binary file not shown.
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,57 @@ | ||
import { database } from "./db/index.ts"; | ||
|
||
const databaseList: {[key: string]: Array<Object>} = { | ||
mongodb: [ | ||
{ | ||
url: 'mongodb://127.0.0.1/', | ||
database: 'Testing' | ||
} | ||
] | ||
} | ||
|
||
class Database { | ||
connection: Array<any>; | ||
connection_driver: any; | ||
dbname: string; | ||
constructor (databaseConnection: any, dbname: string) { | ||
this.connection = []; | ||
this.connection_driver = databaseConnection; | ||
this.dbname = dbname; | ||
} | ||
|
||
getConnection (number?: number) { | ||
if (!number) { | ||
number = 0; | ||
} | ||
if (this.connection[number]) { | ||
return this.connection[number]; | ||
} else { | ||
if (databaseList[this.dbname].hasOwnProperty(number)) { | ||
this.connection[number] = this.connection_driver(databaseList[this.dbname][number]); | ||
return this.connection[number] | ||
} else { | ||
console.warn(`app:database Database ${this.dbname} number ${number} is not exist on configuration !`) | ||
return null | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
const connectAll = () => { | ||
let conn: {[key: string]: any} = {}; | ||
for (const dbname in databaseList) { | ||
conn[dbname] = [] | ||
for (var i = 0; i < databaseList[dbname].length; i++) { | ||
conn[dbname].push(database(dbname, i)); | ||
} | ||
} | ||
return conn; | ||
} | ||
|
||
|
||
|
||
export { | ||
connectAll, | ||
Database | ||
} |
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,10 @@ | ||
import { Connection as mongoConnection } from './mongodb.db.ts'; | ||
|
||
function database (dbname: string, number?: number) { | ||
if (!number) number = 0; | ||
if (dbname == 'mongodb') { | ||
return mongoConnection.getConnection(number); | ||
} | ||
} | ||
|
||
export { database } |
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,16 @@ | ||
import { Database } from "../database.ts"; | ||
import { MongoClient } from "../../../modules/deps.ts"; | ||
|
||
const mongoConnect = (config: {[key: string]: string}) => { | ||
const client = new MongoClient(); | ||
client.connectWithUri(config.url); | ||
let db = client.database(config.database); | ||
return db; | ||
} | ||
|
||
let Connection = new Database(mongoConnect, 'mongodb'); | ||
|
||
export { | ||
Connection, | ||
mongoConnect | ||
} |
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 @@ | ||
export { database } from './db/index.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
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,15 @@ | ||
import { database } from '../bootstrap/index.ts'; | ||
|
||
const db = database("mongodb"); | ||
const User = db.collection("users"); | ||
|
||
async function getUsers (params?: object): Promise<object> { | ||
return await User.find(params); | ||
} | ||
|
||
const users = { | ||
getUsers | ||
} | ||
export { | ||
users | ||
} |
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,15 @@ | ||
export { | ||
App, | ||
Request, | ||
Response, | ||
Router, | ||
logger, | ||
parser, | ||
staticServe | ||
} from "https://deno.land/x/attain/mod.ts"; | ||
|
||
export { MongoClient } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
export { | ||
serve | ||
} from "https://deno.land/[email protected]/http/server.ts"; |
This file was deleted.
Oops, something went wrong.