Skip to content

Commit

Permalink
Update wa-sqlite version
Browse files Browse the repository at this point in the history
  • Loading branch information
mugikhan committed Apr 18, 2024
1 parent 89f6b7c commit 243f8e9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
3 changes: 2 additions & 1 deletion demos/react-supabase-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"dependencies": {
"@journeyapps/powersync-react": "workspace:*",
"@journeyapps/powersync-sdk-web": "workspace:*",
"@journeyapps/wa-sqlite": "~0.1.1",
"@journeyapps/wa-sqlite": "~0.2.0",
"@mui/material": "^5.15.12",
"@mui/x-data-grid": "^6.19.6",
"@mui/icons-material": "^5.15.12",
"@supabase/supabase-js": "^2.39.7",
"js-logger": "^1.6.1",
"lodash": "^4.17.21",
Expand Down
17 changes: 13 additions & 4 deletions demos/react-supabase-todolist/src/app/utils/fts_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { db } from '@/components/providers/SystemProvider';

/**
* adding * to the end of the search term will match any word that starts with the search term
* e.g. searching bl will match blue, black, etc.
* consult FTS5 Full-text Query Syntax documentation for more options
* @param searchTerm
* @returns a modified search term with options.
*/
function createSearchTermWithOptions(searchTerm: string): string {
// adding * to the end of the search term will match any word that starts with the search term
// e.g. searching bl will match blue, black, etc.
// consult FTS5 Full-text Query Syntax documentation for more options
const searchTermWithOptions: string = `${searchTerm}*`;
return searchTermWithOptions;
}

/// Search the FTS table for the given searchTerm
/**
* Search the FTS table for the given searchTerm
* @param searchTerm
* @param tableName
* @returns results from the FTS table
*/
export async function searchTable(searchTerm: string, tableName: string): Promise<any[]> {
const searchTermWithOptions = createSearchTermWithOptions(searchTerm);
return await db.getAll(`SELECT * FROM fts_${tableName} WHERE fts_${tableName} MATCH ? ORDER BY rank`, [
Expand Down
21 changes: 14 additions & 7 deletions demos/react-supabase-todolist/src/app/utils/fts_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { Table } from '@journeyapps/powersync-sdk-web';
import { db } from '@/components/providers/SystemProvider';
import { ExtractType, generateJsonExtracts } from './helpers';

/// Create a Full Text Search table for the given table and columns
/// with an option to use a different tokenizer otherwise it defaults
/// to unicode61. It also creates the triggers that keep the FTS table
/// and the PowerSync table in sync.
/**
* Create a Full Text Search table for the given table and columns
* with an option to use a different tokenizer otherwise it defaults
* to unicode61. It also creates the triggers that keep the FTS table
* and the PowerSync table in sync.
* @param tableName
* @param columns
* @param tokenizationMethod
*/
async function createFtsTable(tableName: string, columns: string[], tokenizationMethod = 'unicode61'): Promise<void> {
const internalName = (AppSchema.tables as Table[]).find((table) => table.name === tableName)?.internalName;
const stringColumns = columns.join(', ');
Expand Down Expand Up @@ -49,9 +54,11 @@ async function createFtsTable(tableName: string, columns: string[], tokenization
});
}

/// This is where you can add more methods to generate FTS tables
/// that correspond to the tables in your schema and populate them
/// with the data you would like to search on
/**
* This is where you can add more methods to generate FTS tables in this demo
* that correspond to the tables in your schema and populate them
* with the data you would like to search on
*/
export async function configureFts(): Promise<void> {
await createFtsTable('lists', ['name'], 'porter unicode61');
await createFtsTable('todos', ['description', 'list_id']);
Expand Down
4 changes: 2 additions & 2 deletions packages/powersync-sdk-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"author": "JOURNEYAPPS",
"license": "Apache-2.0",
"devDependencies": {
"@journeyapps/wa-sqlite": "~0.1.1",
"@journeyapps/wa-sqlite": "~0.2.0",
"@types/lodash": "^4.14.200",
"@types/uuid": "^9.0.6",
"@vitest/browser": "^1.3.1",
Expand All @@ -45,7 +45,7 @@
"webdriverio": "^8.32.3"
},
"peerDependencies": {
"@journeyapps/wa-sqlite": "~0.1.1"
"@journeyapps/wa-sqlite": "~0.2.0"
},
"dependencies": {
"@journeyapps/powersync-sdk-common": "workspace:*",
Expand Down
50 changes: 36 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 243f8e9

Please sign in to comment.