Using In Your App
Installing Into Your App
npm install @slaypics/slay-q
Additionally, you'll need to select a driver package to connect to your database:
@slay-pics/slay-q-supabase
- Supabase driver that uses@supabase/supabase-js
to connect to supabase.@slay-pics/slay-q-postgres
- Driver that talks directly to Postgres viapg
package.@slay-pics/slay-q-rpc
- Driver that talks to aslay-q-ingest
instance. The Slay Q ingest is an HTTP RPC server. See the nuxt example app for an example of its use.
If the bulk of your app is using supabase-js
to access Supabase then choose the Supabase driver. Otherwise, if you are using
something like pg
, drizzle
or knex
then use the Postgres driver.
If you'd like to futureproof your app a little, using the RPC driver but know that you'll have to deploy the RPC Ingest Server alongside the SlayQ server. It deploys easily on Vercel and other serverless providers.
Environment Variables
You can configure the driver by passing in options to the constructor, or alternatively you can specify the following environment variables,
For the supabase driver:
SUPABASE_URL
- URL to your supabase instanceSUPABASE-SERVICE-KEY
- Service key for your supabase instance
For the postgres driver:
DATABASE_URL
- The database connection string url
For the Ingest RPC driver:
SLAY_Q_WORKER_SECRET
- Shared secret used to validate RPC requestsSLAY_Q_INGEST_ENDPOINT
- URL to the slay-q ingest endpoint
Running the Dev Server
To get started quickly, you can run the dev server locally:
npx giget@latest giget@latest bitbucket:slay-pics/slay-utils/docker slayq-docker
cd slayq-docker
docker compose up -d
This will launch three containers: a postgres instance, the Slay Ingest RPC server and the SlayQ server. You should configure your client (read more) with the RPC driver using the following environment variables and values:
SLAY_Q_WORKER_SECRET=G,4DgB$.?>X]"w}w1745Xq2nKoM4BG74
SLAY_Q_INGEST_ENDPOINT=http://localhost:3012
Next Steps
Once you've installed the packages and have the dev server running: