Kysoql

Framework

Build Salesforce SOQL with a Kysely-inspired, type-safe TypeScript query builder.

Kysoql gives Salesforce SOQL a fluent, type-safe TypeScript API. You write queries with familiar builder methods, while the generated schema keeps object names, fields, relationships, and supported operations tied to your Salesforce org.

If you know Kysely, the shape of the API should feel familiar. Kysoql is still its own query builder. It targets SOQL directly and follows Salesforce rules whenever SQL and SOQL behave differently.

Start here

The getting started guide takes you from installation to a real REST query. If you only want to see the builder first, this is the basic idea:

import { Kysoql } from "@kysoql/core";
import type { SalesforceSchema } from "./kysoql/salesforce.generated";

const db = new Kysoql<SalesforceSchema>();

const query = db
  .selectFrom("Account")
  .select(["Id", "Name"])
  .where("Name", "like", "Acme%")
  .orderBy("Name")
  .limit(25);

console.log(query.compile().soql);
// SELECT Id, Name FROM Account WHERE Name LIKE 'Acme%' ORDER BY Name LIMIT 25

Compilation does not need a Salesforce connection. Add an executor when you want .execute() and related methods to send the query to Salesforce.

What feels familiar from Kysely?

The important difference is the target language. SOQL uses relationship paths, parent-to-child subqueries, and semi-joins instead of arbitrary SQL joins. Ordinary API values become escaped SOQL literals rather than SQL placeholder parameters. Mutations and transactions live outside this package because they are not part of SOQL.

Packages

PackageWhat it does
@kysoql/coreBuilds and compiles typed SOQL queries.
@kysoql/restExecutes queries with Salesforce REST and native fetch.
@kysoql/authHandles supported Salesforce OAuth flows and refresh-token storage.
@kysoql/codegenGenerates org-specific TypeScript schema metadata.
@kysoql/jsforceConnects Kysoql to an existing JSforce connection.

Install only the pieces your application needs, but keep all @kysoql/* packages on aligned versions.

Find the right guide

I want to...Read
Understand how builders and result types workMental model
Choose fields and shape a resultSelecting fields
Build WHERE conditionsFiltering records
Query parent or child relationshipsRelationships
Build grouped reportsCounts and aggregate reports
Sort or paginate resultsOrdering and pagination
Run queries through Salesforce RESTNative REST execution
Compile SOQL for ApexCompile for Apex
Check a platform-specific restrictionSupport boundaries and limits
Diagnose an errorTroubleshooting
Look up a public APICore API reference

Types help, Salesforce still decides

Generated metadata catches a lot before runtime, including invalid names, unsupported operators, and many incompatible query shapes. It cannot replace Salesforce itself.

Permissions, enabled org features, API-version behaviour, query selectivity, current metadata, and runtime limits still apply when Salesforce receives the query.

Beta and Pilot features live under Beta and pilot features so they do not blend into the normal production API. soql.raw() remains the explicit escape hatch for trusted syntax Kysoql does not model.

For a direct map from builder concepts to Salesforce documentation, use the Salesforce reference map.

On this page