ParadeDB JavaScript Client Library
ParadeDB is an Elasticsearch alternative built on Postgres. We're modernizing the features of Elasticsearch's product suite, starting with real-time search and analytics.
Test successfully with
Package | Version |
---|---|
paradedb-js | |
@mwcp/paradedb |
npm i paradedb
// OR
npm i @mwcp/paradedb
-
Initialize ParadeDb instance
import { ParadeDb, type DbConnectionConfig } from 'paradedb' const connection: DbConnectionConfig = { host: process.env['PARADEDB_HOST'] ? process.env['PARADEDB_HOST'] : 'localhost', port: process.env['PARADEDB_PORT'] ? +process.env['PARADEDB_PORT'] : 5432, database: process.env['PARADEDB_DB'] ? process.env['PARADEDB_DB'] : 'postgres', user: process.env['PARADEDB_USER'] ? process.env['PARADEDB_USER'] : 'postgres', password: process.env['PARADEDB_PASSWORD'] ? process.env['PARADEDB_PASSWORD'] : 'password', } const pdb = new ParadeDb('master', { connection })
-
const options: CreateBm25Options = { indexName: 'search_idx', tableName: 'mock_items', keyField: 'id', } await pdb.index.createBm25(options)
-
const options: DropBm25Options = { indexName: 'search_idx', } await pdb.index.dropBm25(options)
-
const rows: IndexSchemaDto[] = await idx.schema({ indexName: 'search_idx' }) assert(rows.length, 'Not found')
-
const size: bigint = await idx.size({ indexName: 'search_idx' }) // 0n means not found
Basic Usage:
const pdb = new ParadeDb('test', dbConfig)
const rows = await pdb.search<MockItemsDo>('mock_items')
.whereRaw(`description @@@ :k1`, { k1: 'keyboard' })
.orderBy('id', 'desc')
.limit(limit)
Update project src/configuration.ts
import { Configuration } from '@midwayjs/core'
import * as pdb from '@mwcp/paradedb'
@Configuration({
imports: [ pdb ],
importConfigs: [join(__dirname, 'config')],
})
export class ContainerConfiguration implements ILifeCycle {
}