jsx-sql

0.0.1 • Public • Published

jsx-sql

npm version build codecov License

ko-fi

Overview

A SQL notation that mimic JSX.

Notes

Original Image from X

Installation

You can install this library using npm:

npm install jsx-sql

Usage

  1. Create SQLite3 database.
touch ./db/sqlite.db
  1. Insert data into database.
sqlite3 db/sqlite.db < db/init.sql
  1. Wrap your app with the SQLProvider and provide dbPath 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>
  );
}

API

Hooks

  • query(node) - Build SQL query by JSX.Element and fetch data from DB.

SQLProvider

The SQLProvider component should be used to wrap your app.

Link

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependents (0)

Package Sidebar

Install

npm i jsx-sql

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

171 kB

Total Files

25

Last publish

Collaborators

  • hidaka