FRecord is a unique syntax for the F8 platform. It’s primarily used for database operations (read, write, etc) instead of writing SQL queries.
Common Usage
Listed here are several common usage examples of FRecord
Query Syntax
Most FRecord searches performed within the platform will leverage the following format
var variableName = new FRecord(bucketName);
variableName.addSearch(slotName, slotValue);
variableName.addSearch(slotName, slotValue);
variableName.search();
while (variableName.next()) {
//Do something with each FRecord found
}
Insert/Update Syntax
To insert or update using FRecord, you'll use the following format
var recordVar = new FRecord(bucketName); recordVar.slotName = newValue; recordVar.slotName = newValue; recordVar.slotName = newValue; recordVar.slotName = newValue; recordVar.update(); // or .insert()
Basic Search
Show a list of all users and log out the first and last name of each user found
var userVar = new FRecord('user');
userVar.search();
while (userVar.next()) {
console.log('Found user - ' + userVar.first_name + ' ' + userVar.last_name);
}
Advanced Search
Show a list of all active male users
var userVar = new FRecord('user');
userVar.addSearch('gender', 'male');
userVar.addSearchIsTrue('active');
userVar.search();
while (userVar.next()) {
console.log('Found user - ' + userVar.name);
}
Search and Update
Show a list of all active users created before 2016 and update their active status to false
var firstOf2016InMilliseconds = 1451606400000;
var userVar = new FRecord('user');
userVar.addSearchLessThan('created', firstOf2016InMilliseconds);
userVar.addSearchIsTrue('active');
userVar.search();
while (userVar.next()) {
//Now update each record's active flag
userVar.active = false;
userVar.update();
}
Search, Update, and then Insert a Speak
Same as above. Show a list of all active users created before 2016 and update their active status to false. But then add a "Speak" record
//Lookup the active users created before this year
var firstOf2016InMilliseconds = 1451606400000;
var userVar = new FRecord('user');
userVar.addSearchLessThan('created', firstOf2016InMilliseconds);
userVar.addSearchIsTrue('active');
userVar.search();
while (userVar.next()) {
//Now update each record's active flag
userVar.active = false;
userVar.update();
//Now add a speak record to log the change
var speakVar = new FRecord('speaks');
speakVar.bucket = 'user';
speakVar.record = userVar.id; //Note that we used the userVar variable from the above query
speakVar.text = "User inactivated as it was created prior to 2016";
speakVar.insert();
}
FRecord OR Query
Here is an example of an OR query. Note that the system defaults to an AND query.
var fr = new FRecord('user');
fr.addSearch('first_name', 'John');
fr.getSearchGroup().OR();
fr.addSearch('last_name', 'Doe');
fr.search(function(row) {
console.log(row.name);
});
Methods (work in progress)
| Details | Returns
|
|---|---|
accessToRead()
|
true if can read and false if can not read |
accessToWrite()
|
true is can write and false if can not write |
hasSearch()
|
No results for this method yet |
isIdSearch()
|
TBD |
isNewRecord()
|
true if new, false if not |
isCollectionBucket()
|
true if a collection, false if not |
isConfigBucket()
|
true if a config bucket, false if not |
isValidBucket()
|
true if bucket is valid, false if not |
isValidSlot(slotName)
|
true if slot is valid, false if not |
isVirtualSlot(slotName)
|
true if slot is virtual, false if not |
isInsertOnlySlot(slotName)
|
true if slot is insert only, false if not |
isInternalSlot(slotName)
|
true if slot is internal, false if not |
isInstanceOf()
|
No results for this method yet |
gotoTop()
|
No results for this method yet |
hasNext()
|
No results for this method yet |
next()
|
No results for this method yet |
hasChanged()
|
No results for this method yet |
matches()
|
No results for this method yet |
newRecord()
|
No results for this method yet |
FRecordapi()
|
No results for this method yet |
insert()
|
No results for this method yet |
update()
|
No results for this method yet |
updateMultiple()
|
No results for this method yet |
del()
|
No results for this method yet |
addEncodedSearch(searchQuery, variables(optional))
|
No results for this method yet |
addSearchIsTrue()
|
No results for this method yet |
addSearchIsFalse()
|
No results for this method yet |
addSearch()
|
No results for this method yet |
addSearchStartsWith(slot, value)
|
No results for this method yet |
addSearchLessThan(slot, value)
|
No results for this method yet |
addSearchLessThanEquals(slot, value)
|
No results for this method yet |
addSearchGreaterThan(slot, value)
|
No results for this method yet |
addSearchGreaterThanEquals(slot, value)
|
No results for this method yet |
addSearchContains(slot, value)
|
No results for this method yet |
addSearchNotContains(slot, value)
|
No results for this method yet
|
addSearchEndsWith()
|
No results for this method yet |
addSearchNotEquals()
|
No results for this method yet |
copyRecord()
|
No results for this method yet |
createBucket()
|
No results for this method yet |
syncBucket()
|
No results for this method yet |
createSlot()
|
No results for this method yet |
addSort(slotName, descending (boolean, default false))
|
N/A |
search()
|
No results for this method yet |
setLimit()
|
No results for this method yet |
setWindowPage()
|
No results for this method yet |
setValues()
|
No results for this method yet |
setValuesFromMap()
|
No results for this method yet |
setLoading()
|
No results for this method yet |
isLoading()
|
No results for this method yet |
setTrackChanges()
|
No results for this method yet |
setAllowInternalSlotUpdate()
|
No results for this method yet |
setTriggers()
|
No results for this method yet |
setValidation()
|
No results for this method yet |
setFullRow()
|
No results for this method yet |
setFullCount()
|
No results for this method yet |
setResolveReferences()
|
No results for this method yet |
setSecurityChecks()
|
No results for this method yet |
setValue()
|
No results for this method yet |
getValue()
|
No results for this method yet |
getRowCount()
|
No results for this method yet |
getFullRowCount()
|
No results for this method yet |
getRecord()
|
No results for this method yet |
getRecords()
|
No results for this method yet |
getCollectionParentBuckets()
|
No results for this method yet |
getCollectionChildBuckets()
|
No results for this method yet |
toSetValuesMap()
|
No results for this method yet |
hasAttribute()
|
No results for this method yet |
getAttribute()
|
No results for this method yet |
getLabel()
|
No results for this method yet |
getLabelP()
|
No results for this method yet |
getIntId()
|
No results for this method yet |
getBucketName()
|
No results for this method yet |
getCollectionBucketName()
|
No results for this method yet |
getSlotNames()
|
No results for this method yet |
getSlots()
|
No results for this method yet |
getSlotTypes()
|
No results for this method yet |
getSlotObject()
|
No results for this method yet |
getSearchGroup()
|
No results for this method yet |
getSlotDefinition()
|
No results for this method yet |
getDisplayField()
|
No results for this method yet |
getRecordDisplayValue()
|
No results for this method yet |
getDisplayValue()
|
No results for this method yet |
unloadToJSON()
|
No results for this method yet |
rowToJSON()
|
No results for this method yet |
rowsToJSON()
|
No results for this method yet |
toJSON()
|
No results for this method yet |
toRecordIntIds()
|
No results for this method yet |
toCRC()
|
No results for this method yet |
lock()
|
No results for this method yet |
unlock()
|
No results for this method yet |
getClientMessages()
|
No results for this method yet |
Method Detail
accessToRead
public boolean jsFunction_accessToRead()
- Check to see if there is access to read the FRecord
- Returns:
- Boolean - true if can read and false if can not read.
- Example:
var userVar = new FRecord('user');
userVar.search();
if (userVar.next()) {
var hasRead = userVar.accessToRead();
}
accessToWrite
public boolean jsFunction_accessToRead()
- Check to see if there is access to write to the FRecord
- Returns:
- Boolean - true if can read and false if can not write.
- Example:
var userVar = new FRecord('user');
userVar.search();
if (userVar.next()) {
var hasWrite = userVar.accessToWrite();
}
isNewRecord
public boolean jsFunction_isNewRecord()
- Check to see if the FRecord is new (e.g. hasn't been inserted yet)
- Returns:
- Boolean - true if record is new and false not
- Example:
if ($record.isNewRecord()) {
//Set name to first + last
$record.name = $record.first_name + ' ' + $record.last_name;
$record.update();
}
addSort
public boolean jsFunction_addSort()(slotName, descending (boolean, default false))
- Sort the results returned by a column value, and sort either ascending or descending
- Example:
var userVar = new FRecord('user');
userVar.addSort('created', true);
userVar.search();
if (userVar.next()) {
console.log('Found user record - ' + userVar.name);
}
addEncodedSearch
void jsFunction_addEncodedSearch(searchQuery, variables(optional))
- FRecord search via encoded search query
- Example:
var userVar = new FRecord('user');
userVar.addEncodedSearch([["first_name","begins","Chris"],["last_name","contains","Burk"]])
userVar.search();
if (userVar.next()) {
console.log("User: " + userVar.name);
}
- Note: For an easy way to build a search query create a filter using the filter builder on the list component, copy everything after the q= in the URL
