Skip to content

Commit

Permalink
fix: Fix pg and mysql proxy examples
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanNabukhotnyi committed Oct 4, 2023
1 parent d1d16d9 commit 968ee62
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
12 changes: 12 additions & 0 deletions examples/mysql-proxy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/mysql-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"axios": "^1.5.1",
"express": "^4.18.2",
"express-rate-limit": "^7.0.2",
"mysql2": "^3.6.1"
},
"devDependencies": {
Expand Down
13 changes: 12 additions & 1 deletion examples/mysql-proxy/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import * as mysql from 'mysql2/promise';
import express from 'express';
import RateLimit from 'express-rate-limit';

const app = express();

const limiter = RateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per windowMs
});

app.use(express.json());
app.use(limiter);
const port = 3000;

const main = async () => {
const connection = await mysql.createConnection('mysql://root:[email protected]:5432/drizzle');

app.post('/query', async (req, res) => {
const { sql: sqlBody, params, method } = req.body;
const { sql, params, method } = req.body;

// prevent multiple queries
const sqlBody = sql.replace(/;/g, '');

if (method === 'all') {
try {
Expand Down
12 changes: 12 additions & 0 deletions examples/pg-proxy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/pg-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"axios": "^1.5.1",
"express": "^4.18.2",
"drizzle-orm": "workspace:../../drizzle-orm/dist",
"express-rate-limit": "^7.0.2",
"pg": "^8.11.3"
},
"devDependencies": {
Expand Down
13 changes: 12 additions & 1 deletion examples/pg-proxy/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { Client } from 'pg';
import express from 'express';
import RateLimit from 'express-rate-limit';

const app = express();

const limiter = RateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per windowMs
});

app.use(express.json());
app.use(limiter);
const port = 3000;

const client = new Client('postgres://postgres:postgres@localhost:5432/postgres');

app.post('/query', async (req, res) => {
const { sql: sqlBody, params, method } = req.body;
const { sql, params, method } = req.body;

// prevent multiple queries
const sqlBody = sql.replace(/;/g, '');

if (method === 'all') {
try {
Expand Down

0 comments on commit 968ee62

Please sign in to comment.