Table of Contents

Sqlite

This module implement a native binding to a Sqlite database. It enables JavaScript programs to create, access, and query Sqlite databases.

Use ` from "hop:sqlite"` to use it.* import

Sqlite module is intended to be compatible with the Nodejs Sqlite3.

Functions

sqlite.Database(filename [, mode] [, callback])

Example

This example shows how to use the native Sqlite binding.

sqlite/sqlite.js

var Sqlite = require( './sqlite_core.js' ).Sqlite;
var path = require( 'path' );
var np = require( hop.notepad );

var defpath = path.join( path.dirname( module.filename ), "db.sqlite" );

service sqlite( o ) {
   var path = o && "path" in o ? o.path : defpath;
   var db = new Sqlite( path );

   return <html>
     <head css=${np.css} jscript=${np.jscript}/>
     <np.notepad>
        ${db.tables().map( function( t ) {
           return <np.nptab>
             <np.nptabhead> ${ t } </np.nptabhead>
              ${dbTable( db, t )}
           </np.nptab>
        } )}
     </np.notepad>
   </html>
}

function dbTable( db, table ) {
   var cols = db.columns( table );

   return <table>
     <tr>
       <th/>
       ${cols.map( function( c ) { return <th/> })}
     </tr>
      ${db.map( function( row ) {
         return <tr>${row.map( function( e ) { return <td> ${ e } </td> } )}</tr>
      }, "SELECT rowid, * FROM " + table +" ORDER BY rowid" )}
   </table>
}
   
console.log( "Go to \"http://%s:%d/hop/sqlite\"", hop.hostname, hop.port );