-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
Conversation
examples/mysql-proxy/src/server.ts
Outdated
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
a database access
This route handler performs
a database access
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
a database access
This route handler performs
a database access
This route handler performs
a database access
This route handler performs
a database access
examples/pg-proxy/src/server.ts
Outdated
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
a database access
This route handler performs
a database access
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
a database access
This route handler performs
a database access
This route handler performs
a database access
This route handler performs
Postgres and MySQL HTTP proxy implementations with examples