SQL 🤝 hyperscript.
SQL database running in the browser
- include sql.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.10.3/sql-wasm.js"></script>
- include _hyperscript
<script src="https://unpkg.com/hyperscript.org@0.9.12/dist/_hyperscript.min.js"></script>
- include _hsql:
<script src="https://cdn.jsdelivr.net/gh/Storm-Consulting/_hsql/index.min.js"></script>
db 'CREATE TABLE users (firstname CHAR(50) NOT NULL, lastname CHAR(50) NOT NULL, age INT(3) NOT NULL)'
db 'INSERT INTO users VALUES (?,?,?)' with ['John', 'Doe', 27]
db 'INSERT INTO users VALUES ($firstname,$lastname,$age)' with {$firstname: 'John', $lastname: 'Doe', $age: 27}
errors can be handled using catch
:
db 'INSERT INTO users VALUES (?,?,?)' with record
catch error
// Handle errors...
HTML
<input id="firstname" value="John" type="text">
<input id="lastname" value="Doe" type="text">
<input id="age" value="27" type="number">
hyperscript
set record to [#firstname.value, #lastname.value, #age.value as a Number]
db 'INSERT INTO users VALUES (?,?,?)' with record
table it // "it" is the result of the db command
put it into #results // HTML
- Integration of SQL.js
- Running direct statements against SQL.js
- Running prepared statements against SQL.js
- Responding with HTML
- Native SQL statements using hyperscript (
dbselect * from users where id = <#id/>.value
)