Skip to content

Commit

Permalink
easier test for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Nicolle committed Oct 31, 2023
1 parent cc83086 commit db456dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 10 additions & 3 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Grid } from 'grid';
import { Idatabase, SupaDB } from 'database';

import { Idatabase, SupaDB, setDatabase } from 'database';
import axios from 'axios';
const debugMigration = false;
class API {
public idb: Idatabase;
public supadb: SupaDB;
public _mode: string;
constructor(mode: string = 'unknown') {
this.idb = new Idatabase();
let prepromise: Promise<unknown> = Promise.resolve();
if (debugMigration) {
prepromise = prepromise
.then(() => axios.get('/test-db.json'))
.then(({ data }) => setDatabase(data, 4))
}
this.idb = new Idatabase(prepromise);
this.supadb = new SupaDB('https://tnvxmrqhkdlynhtdzmpw.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InRudnhtcnFoa2RseW5odGR6bXB3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODIyNTM0MTEsImV4cCI6MTk5NzgyOTQxMX0.4PczPPAxbkwBvig7NTHNbR8JumuwPPqfyS_kGnkxP5I');
this._mode = mode;
}
Expand Down
13 changes: 8 additions & 5 deletions database/src/idb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ async function create() {

export class Idatabase extends Database {
private loadingPromise: ReturnType<typeof create>;
constructor() {
constructor(prepromise?: Promise<unknown>) {
super();
this.loadingPromise = create()
if (!prepromise) {
prepromise = Promise.resolve();
}
this.loadingPromise = prepromise.then(() => create())
.then((db) => {
return db.get('styles', defaultStyles.id)
.then((style) => style ? Promise.resolve('')
Expand Down Expand Up @@ -266,18 +269,18 @@ export function setDatabase(json: any, version: number) {
const objstore = db.createObjectStore(key, {
keyPath: 'id',
});
if(key === 'words'){
if (key === 'words') {
// @ts-ignore
objstore.createIndex('by-word', 'id');
}else{
} else {
// @ts-ignore
objstore.createIndex('by-id', 'id');
}
console.log('creating', key);
// @ts-ignore
const store = transaction.objectStore(key);
promise = promise
// @ts-ignore
// @ts-ignore
.then(() => Promise.all(values.map((value: any) => store.put(value))))
});
}
Expand Down

0 comments on commit db456dd

Please sign in to comment.