[Pas2js] Project SQLite for pas2js

Michael Van Canneyt michael at freepascal.org
Tue Sep 22 20:54:03 CEST 2020



On Tue, 22 Sep 2020, warleyalex via Pas2js wrote:

> OK, It is a bit of investigation, and no need to Disable Cache at developer
> tools,
>
> Look at the following method (the fetch method with the object
> initialization {cache: "no-store"}) 
>
> {  Open Async local Sqlite Database file }
> procedure OpenSQLiteDBFile(path: String; callBackDB: TProcedureSQLDB);
> async;
> var
>  fetched: TJSResponse;
>  buf: TJSPromise; //TJSArrayBuffer;
>  dataDB: TJSUint8Array;
> begin
>  fetched := await(window.fetch( path, new(['cache', 'no-store']) ));
>  buf := await (fetched.arrayBuffer());
>  dataDB:= TJSUint8Array.New( TJSArrayBuffer(buf) );
>  callBackDB( TJSSqliteDatabase.New( dataDB )); 
> end; 
>
>
> By the way, I had to edit web.pas, I think the correct definition of the
> following method would be correct;
>
> function fetch(resource: String; init: TJSObject): TJSResponse;
> {TJSPromise;} overload; external name 'fetch';


Fetch returns a promise, not a TJSResponse.

See

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch

So you will at least need an async modifier if you want to have it return a
'JSResponse'

But for backwards compatibility, this cannot be added with the name 'fetch'.

So I have added it with the name asyncfetch.

Michael.


More information about the Pas2js mailing list