Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sail-sail/sail_sqlstring
Simple SQL escape and format for MySQL
https://github.com/sail-sail/sail_sqlstring
Last synced: 1 day ago
JSON representation
Simple SQL escape and format for MySQL
- Host: GitHub
- URL: https://github.com/sail-sail/sail_sqlstring
- Owner: sail-sail
- Created: 2022-05-16T03:11:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-16T03:30:45.000Z (over 2 years ago)
- Last Synced: 2025-01-30T00:12:20.446Z (7 days ago)
- Language: TypeScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sail_sqlstring
Simple SQL escape and format for MySQL for deno
## usage
```ts
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { escape, escapeId, format } from "https://deno.land/x/[email protected]/mod.ts";Deno.test("escape", function() {
const userId = "1";
const sql = `select * from user where id = ${ escape(userId) }`;
assertEquals(sql, "select * from user where id = '1'");
});Deno.test("escapeId", function() {
const user = "user";
const sql = `select * from ${ escapeId(user) } where id = '1'`;
assertEquals(sql, "select * from `user` where id = '1'");
});Deno.test("format", function() {
const sql = `select * from user where id = ?`;
const sql2 = format(sql, [ "1" ]);
assertEquals(sql2, "select * from user where id = '1'");
});
```