-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
10 changed files
with
201 additions
and
77 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
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,37 @@ | ||
export default { | ||
/* | ||
*-------------------------------------------------------------------------- | ||
* Default Database Connection Name | ||
*-------------------------------------------------------------------------- | ||
* | ||
* Here you may specify which of the database connections below you wish | ||
* to use as your default connection for all database work. | ||
*/ | ||
|
||
default: process.env.DB_CONNECTION || 'mysql', | ||
|
||
/* | ||
*-------------------------------------------------------------------------- | ||
* Database Connections | ||
*-------------------------------------------------------------------------- | ||
* | ||
* Here are each of the database connections setup for your application. | ||
* Of course, examples of configuring each database platform that is | ||
* supported by Lesgo is shown below to make development simple. | ||
*/ | ||
|
||
connections: { | ||
mysql: { | ||
connection: { | ||
host: process.env.DB_HOST_WRITE || process.env.DB_HOST || '127.0.0.1', | ||
host_read: | ||
process.env.DB_HOST_READ || process.env.DB_HOST || '127.0.0.1', | ||
port: process.env.DB_PORT || 3306, | ||
user: process.env.DB_USER || 'root', | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME || 'myapp_test', | ||
charset: 'utf8', | ||
}, | ||
}, | ||
}, | ||
}; |
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,26 @@ | ||
/* eslint-disable no-console */ | ||
import middy from 'middy'; | ||
import httpMiddleware from 'Middlewares/httpMiddleware'; | ||
import app from 'Config/app'; | ||
import { connectSentry } from 'Utils/sentry'; | ||
import { db, dbRead, connectDb } from 'Utils/db'; | ||
|
||
connectDb(); | ||
connectSentry(); | ||
|
||
const originalHandler = async () => { | ||
// Fetch data from READ HOST | ||
const dataRead = await dbRead.query('SELECT * FROM users LIMIT 1'); | ||
await dbRead.end(); | ||
|
||
// Fetch data from WRITE HOST | ||
const dataWrite = await db.query('SELECT * FROM users LIMIT 1'); | ||
await db.end(); | ||
|
||
return [{ dataRead, dataWrite }]; | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const handler = middy(originalHandler); | ||
|
||
handler.use(httpMiddleware({ debugMode: app.debug })); |
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