SQL 🤝 hyperscript.
SQL database running in the browser
- includesql.js
<scriptsrc= "https://cdnjs.cloudflare /ajax/libs/sql.js/1.10.3/sql-wasm.js"></script>
- include_hyperscript
<scriptsrc= "https://unpkg /[email protected]/dist/_hyperscript.min.js"></script>
- include _hsql:
<scriptsrc= "https://cdn.jsdelivr.net/gh/3c2f3e/_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 usingcatch
:
db'INSERT INTO users VALUES (?,?,?)'withrecord
catcherror
// Handle errors...
HTML
<inputid= "firstname"value= "John"type= "text">
<inputid= "lastname"value= "Doe"type= "text">
<inputid= "age"value= "27"type= "number">
hyperscript
setrecordto[#firstname.value,#lastname.value,#age.valueasaNumber]
db'INSERT INTO users VALUES (?,?,?)'withrecord
tableit// "it" is the result of the db command
putitinto#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
)