New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sqlitecloud/sqlc-react-search

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sqlitecloud/sqlc-react-search

SQLite Cloud search headless component

  • 0.0.14
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Install

You can install @sqlitecloud/sqlc-react-search via the terminal by running:

npm i @sqlitecloud/sqlc-react-search

Using

To use the search component, you need to initialize it by passing the URL of the edge function created from the dashboard. More details below.

import { useSqlcSearch } from "@sqlitecloud/sqlc-react-search";

function Search() {
  const searchUrl = "https://myhost.sqlite.cloud:8090/v2/functions/search-js";

  // Initialize the useSqlcSearch custom hook
  const {
    searchText,    // Text to search for
    searchRes,     // Search results
    searchError,   // Error information if search fails
    validSearchUrl,// Boolean indicating if the search URL is valid
    handleSearch,  // Function to handle search input changes
  } = useSqlcSearch(searchUrl);

  return (
    <div>
      <input
        type="text"
        value={searchText}
        onChange={handleSearch}
        placeholder="Type here..."
      />
      <pre>{JSON.stringify(searchRes, null, 2)}</pre>
    </div>
  )
}

Typescript

The following types can be imported and used:

import type { SearchResult, SearchError, SqlcSearchReturn } from "@sqlitecloud/sqlc-react-search";

Edge Function

The code for the edge function to be created is as follows (Edge Functions documentation):

const query = request.params.query;
const requestid = request.params.requestid;
return {
  data: {
    search: await connection.sql`SELECT url, replace(snippet(documentation, -1, '<b>', '</b>', '...', 10), x'0A', ' ') as 'snippet' FROM documentation WHERE content MATCH concat(${query}, '*') ORDER BY rank LIMIT 256;`,
    requestid: requestid
  }
}
  • Replace documentation with the name of your database.
  • Select JavaScript as the function type.
  • Choose an appropriate API KEY with the correct permission to read from your database. The API KEY can be created from the dashboard's Security/API KEY section.

Demo

LIVE DEMO

We provide a simple example that shows how to use the component in the example folder.

To run the example, download the repo and follow these steps:

  1. Run npm install at the root directory level.
  2. Run npm run start in the ./packages/sqlc-react-search/example subdirectory.

The example code will be executed at localhost:1234

FAQs

Package last updated on 18 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc