A SQL notation that mimic JSX.
- This library is a tribute to the following X-posts.
- Please understand that this is only a joke.
You can install this library using npm:
npm install jsx-sql
- Create SQLite3 database.
touch ./db/sqlite.db
- Insert data into database.
sqlite3 db/sqlite.db < db/init.sql
- Wrap your app with the
SQLProvider
and providedbPath
property.
import { SQLProvider } from "jsx-sql";
ReactDOM.render(
<React.StrictMode>
<SQLProvider dbPath="/db/sqlite.db">
<App />
</SQLProvider>
</React.StrictMode>,
document.getElementById("root"),
);
Use the provided hooks to fetch DB data:
export default function Home() {
const data = query(
<Select>
<Where>
<Column name="status" value="paid" />
<Column name="name" value="bob" />
</Where>
<Limit amount={5} />
</Select>,
);
return (
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{data.map((record, index) => (
<tr key={index}>
<td>{record[0]}</td>
<td>{record[1]}</td>
<td>{record[2]}</td>
</tr>
))}
</tbody>
</table>
);
}
-
query(node)
- Build SQL query by JSX.Element and fetch data from DB.
The SQLProvider
component should be used to wrap your app.
This project is licensed under the MIT License - see the LICENSE file for details.