diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2023-12-12 21:59:35 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2023-12-12 21:59:35 +0100 |
commit | bfc1d39d2c9a9f192d94627f05cdc246219cbc16 (patch) | |
tree | 947b77ec6a1ab441b5ef4f053affef42e4705cc6 /themes | |
parent | d196a3fe620a16d96a7a0bb9ad6eb929939d9570 (diff) | |
download | www-andreasbaumann-cc-bfc1d39d2c9a9f192d94627f05cdc246219cbc16.tar.gz www-andreasbaumann-cc-bfc1d39d2c9a9f192d94627f05cdc246219cbc16.tar.bz2 |
replaced .ajax with XMLHttpRequest, now binary fetches are working
Diffstat (limited to 'themes')
-rw-r--r-- | themes/new_theme/layouts/_default/list.html | 2 | ||||
-rw-r--r-- | themes/new_theme/layouts/partials/ranklist_fts5.html | 77 |
2 files changed, 43 insertions, 36 deletions
diff --git a/themes/new_theme/layouts/_default/list.html b/themes/new_theme/layouts/_default/list.html index c4278e5..4816514 100644 --- a/themes/new_theme/layouts/_default/list.html +++ b/themes/new_theme/layouts/_default/list.html @@ -8,7 +8,7 @@ {{- with .Content }} <div class="content main__content clearfix"> {{ . }} - {{ partial "ranklist_elasticlunr.html" . }} + {{ partial "ranklist_fts5.html" . }} </div> {{- end }} {{ $section := .Section }} diff --git a/themes/new_theme/layouts/partials/ranklist_fts5.html b/themes/new_theme/layouts/partials/ranklist_fts5.html index 3a29507..56ba77c 100644 --- a/themes/new_theme/layouts/partials/ranklist_fts5.html +++ b/themes/new_theme/layouts/partials/ranklist_fts5.html @@ -1,6 +1,7 @@ <script src="/js/jquery.js" type="text/javascript"></script> <script src="/js/url-search-params.js" type="text/javascript"></script> <script src="/js/loadingoverlay.min.js" type="text/javascript"></script> +<script src="/js/require.js" type="text/javascript"></script> <script src="/js/sql-fts5.js" type="module"></script> <script language="Javascript"> @@ -28,44 +29,50 @@ function hexdump(buffer, blockSize) { return lines.join("\n"); } - function executeQuery( query ) { + function executeQuery( query ) { $( "#query" ).LoadingOverlay( "show" ); - $.ajax( { - type : 'GET', - url : '/index/posts.db', - cache : false, - timeout : 5000 - } ) - .error( function( x, t, m ) { - var html = ''; - if( x.status > 0 ) { - msg = x.responseText; - } else { - msg = t; - } - msg = escapeHtml( msg ); - html = "<pre><font color='red'>There was an error loading the Sqlite3/FTS5 index, reason: " + msg + "</font></pre>\n"; - $( '#ranklist' ).html( html ); - - $( "#query" ).LoadingOverlay( "hide", true ); - } ) - .success( function( data ) { - - var uInt8Array = new Uint8Array( data ); - //~ var html = "<pre>" + hexdump( data , 16 ) + "</pre>"; - //~ var db = new SQL.Database(uInt8Array); - //~ var contents = db.exec("SELECT * FROM my_table"); + console.log( "here" ); - var html = "<pre>ranklist" + db + "</pre>"; - - $( '#ranklist' ).html( html ); - - - $( "#query" ).LoadingOverlay( "hide" ); - } ); - - $( "#query" ).LoadingOverlay( "hide", true ); + const xhr = new XMLHttpRequest(); + xhr.open('GET', '/index/posts.db', true); + xhr.responseType = 'arraybuffer'; + console.log( "here" ); + xhr.onload = e => { + const uInt8Array = new Uint8Array(xhr.response); + console.log( uInt8Array ); + requirejs(["/js/sql-wasm.js"], function(initSqlJs) { + const SQL = initSqlJs({ + locateFile: file => `http://localhost:1313/js/${file}` + }); + initSqlJs().then( function( SQL ) { + var db = new SQL.Database(uInt8Array); + //~ const stmt = db.prepare("SELECT sqlite_version()"); + const stmt = db.prepare( "select uri,highlight(posts, 1, '<b>', '</b>'),snippet(posts, 2, '<b>', '</b>', '...', 50) from posts where posts MATCH 'OpenBSD' ORDER BY bm25(posts) limit 5 offset 0" ); + //~ var stmt = db.prepare( "select * from sqlite_master" ); + //~ const result = stmt.getAsObject({':aval' : 1, ':bval' : 'world'}); + //~ console.log(result); + //~ while (stmt.step()) console.log(stmt.get()); + stmt.bind({a:1, b:2}); + console.log( stmt); + + var html = "<pre>"; + while(stmt.step()) { // + var row = stmt.getAsObject(); + html += JSON.stringify( row ); + } + stmt.free(); + db.close(); + + html += "</pre>"; + + $( '#ranklist' ).html( html ); + + $( "#query" ).LoadingOverlay( "hide" ); + } ); + } ); + } + xhr.send( ); } $( window ).load( function( ) { |