Skip to content

db

Utility to perform soql queries from LWC

Import

import { db } from 'c/bolt';

Usage

Plain query

export default class myLwc extends LightningElement {
@track Contacts;
async handleClick() {
this.Contacts = await db`SELECT Id, Name FROM Contact`;
}
}

Dynamic Values

export default class myLwc extends LightningElement {
@track Contacts;
@api recordId;
async handleClick() {
const SObjectApiName = 'Contact';
this.Contacts = await db`SELECT Id, Name FROM ${SObjectApiName} WHERE Id = ${this.recordId}`;
}
}

Array of fields

export default class myLwc extends LightningElement {
@track Contacts;
async handleClick() {
const fields = ['Id', 'Name', 'foo__c','bar__c'];
this.Contacts = await db`SELECT ${fields} FROM Contact`;
}
}