Skip to content

waitingsong/paradedb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ParadeDB JavaScript Client Library

GitHub tag License ci codecov

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

Packages

Package Version
paradedb-js main-svg
@mwcp/paradedb cli-svg

Installation

npm i paradedb 
// OR
npm i @mwcp/paradedb

Usage

Index

  • 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 })
  • Create an Index

    const options: CreateBm25Options = {
      indexName: 'search_idx',
      tableName: 'mock_items',
      keyField: 'id',
    }
    await pdb.index.createBm25(options)

    More examples

  • Drop an Index

    const options: DropBm25Options = {
      indexName: 'search_idx',
    }
    await pdb.index.dropBm25(options)
  • Index Schema

    const rows: IndexSchemaDto[] = await idx.schema({ indexName: 'search_idx' })
    assert(rows.length, 'Not found')
  • Index Size

    const size: bigint = await idx.size({ indexName: 'search_idx' })
    // 0n means not found

Full Text Search

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)

Midway.js Component

Configuration

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 {
}

Usage

Example

License

MIT

Languages