Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pg | MySQL] Add postgres and mysql proxies #1329

Merged
merged 6 commits into from
Oct 13, 2023

Conversation

RomanNabukhotnyi
Copy link
Collaborator

Postgres and MySQL HTTP proxy implementations with examples

@AndriiSherman AndriiSherman changed the base branch from main to beta October 4, 2023 09:07
Comment on lines 11 to 51
app.post('/query', async (req, res) => {
const { sql: sqlBody, params, method } = req.body;

if (method === 'all') {
try {
const result = await connection.query({
sql: sqlBody,
values: params,
rowsAsArray: true,
typeCast: function(field: any, next: any) {
if (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {
return field.string();
}
return next();
},
});
res.send(result[0]);
} catch (e: any) {
res.status(500).json({ error: e });
}
} else if (method === 'execute') {
try {
const result = await connection.query({
sql: sqlBody,
values: params,
typeCast: function(field: any, next: any) {
if (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {
return field.string();
}
return next();
},
});

res.send(result);
} catch (e: any) {
res.status(500).json({ error: e });
}
} else {
res.status(500).json({ error: 'Unknown method value' });
}
});

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
Comment on lines +53 to +67
app.post('/migrate', async (req, res) => {
const { queries } = req.body;

await connection.query('BEGIN');
try {
for (const query of queries) {
await connection.query(query);
}
await connection.query('COMMIT');
} catch {
await connection.query('ROLLBACK');
}

res.send({});
});

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
Comment on lines 10 to 38
app.post('/query', async (req, res) => {
const { sql: sqlBody, params, method } = req.body;

if (method === 'all') {
try {
const result = await client.query({
text: sqlBody,
values: params,
rowMode: 'array',
});
res.send(result.rows);
} catch (e: any) {
res.status(500).json({ error: e });
}
} else if (method === 'execute') {
try {
const result = await client.query({
text: sqlBody,
values: params,
});

res.send(result.rows);
} catch (e: any) {
res.status(500).json({ error: e });
}
} else {
res.status(500).json({ error: 'Unknown method value' });
}
});

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
Comment on lines +40 to +54
app.post('/migrate', async (req, res) => {
const { queries } = req.body;

await client.query('BEGIN');
try {
for (const query of queries) {
await client.query(query);
}
await client.query('COMMIT');
} catch {
await client.query('ROLLBACK');
}

res.send({});
});

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
examples/mysql-proxy/src/server.ts Dismissed Show dismissed Hide dismissed
examples/mysql-proxy/src/server.ts Dismissed Show dismissed Hide dismissed
examples/mysql-proxy/src/server.ts Dismissed Show dismissed Hide dismissed
examples/pg-proxy/src/server.ts Dismissed Show dismissed Hide dismissed
@AndriiSherman AndriiSherman merged commit 35f2645 into drizzle-team:beta Oct 13, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants