FRecord

From Dreamtsoft Wiki
Jump to: navigation, search

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()
Check to see if there is access to read the FRecord
true if can read and false if can not read
accessToWrite()
Check to see if there is access to write to the FRecord
true is can write and false if can not write
hasSearch()
No description for this method yet
No results for this method yet
isIdSearch()
TBD
TBD
isNewRecord()
Determine if the FRecord is new (true) or existing (false)
true if new, false if not
isCollectionBucket()
Check to see if the bucket is flagged as a collection
true if a collection, false if not
isConfigBucket()
Check to see if the bucket is flagged as "config"
true if a config bucket, false if not
isValidBucket()
Check to see if the bucket is valid
true if bucket is valid, false if not
isValidSlot(slotName)
Check to see if the slot specified is valid
true if slot is valid, false if not
isVirtualSlot(slotName)
Check to see if the slot is flagged as "virtual"
true if slot is virtual, false if not
isInsertOnlySlot(slotName)
Check to see if the slot is flagged as "insert only", meaning that its only editable until you save the record, at which point it becomes read-only
true if slot is insert only, false if not
isInternalSlot(slotName)
Check to see if the slot is internal, like the created, owner, updated, etc slots
true if slot is internal, false if not
isInstanceOf()
No description for this method yet
No results for this method yet
gotoTop()
No description for this method yet
No results for this method yet
hasNext()
No description for this method yet
No results for this method yet
next()
No description for this method yet
No results for this method yet
hasChanged()
No description for this method yet
No results for this method yet
matches()
No description for this method yet
No results for this method yet
newRecord()
No description for this method yet
No results for this method yet
FRecordapi()
No description for this method yet
No results for this method yet
insert()
No description for this method yet
No results for this method yet
update()
No description for this method yet
No results for this method yet
updateMultiple()
No description for this method yet
No results for this method yet
del()
No description for this method yet
No results for this method yet
addEncodedSearch(searchQuery, variables(optional))
No description for this method yet
No results for this method yet
addSearchIsTrue()
No description for this method yet
No results for this method yet
addSearchIsFalse()
No description for this method yet
No results for this method yet
addSearch()
No description for this method yet
No results for this method yet
addSearchStartsWith(slot, value)
No description for this method yet
No results for this method yet
addSearchLessThan(slot, value)
No description for this method yet
No results for this method yet
addSearchLessThanEquals(slot, value)
No description for this method yet
No results for this method yet
addSearchGreaterThan(slot, value)
No description for this method yet
No results for this method yet
addSearchGreaterThanEquals(slot, value)
No description for this method yet
No results for this method yet
addSearchContains(slot, value)
No description for this method yet
No results for this method yet
addSearchNotContains(slot, value)
No description for this method yet
No results for this method yet


addSearchEndsWith()
No description for this method yet
No results for this method yet
addSearchNotEquals()
No description for this method yet
No results for this method yet
copyRecord()
No description for this method yet
No results for this method yet
createBucket()
No description for this method yet
No results for this method yet
syncBucket()
No description for this method yet
No results for this method yet
createSlot()
No description for this method yet
No results for this method yet
addSort(slotName, descending (boolean, default false))
Sort the results returned by a column value, and sort either ascending or descending
N/A
search()
No description for this method yet
No results for this method yet
setLimit()
No description for this method yet
No results for this method yet
setWindowPage()
No description for this method yet
No results for this method yet
setValues()
No description for this method yet
No results for this method yet
setValuesFromMap()
No description for this method yet
No results for this method yet
setLoading()
No description for this method yet
No results for this method yet
isLoading()
No description for this method yet
No results for this method yet
setTrackChanges()
No description for this method yet
No results for this method yet
setAllowInternalSlotUpdate()
No description for this method yet
No results for this method yet
setTriggers()
No description for this method yet
No results for this method yet
setValidation()
No description for this method yet
No results for this method yet
setFullRow()
No description for this method yet
No results for this method yet
setFullCount()
No description for this method yet
No results for this method yet
setResolveReferences()
No description for this method yet
No results for this method yet
setSecurityChecks()
No description for this method yet
No results for this method yet
setValue()
No description for this method yet
No results for this method yet
getValue()
No description for this method yet
No results for this method yet
getRowCount()
No description for this method yet
No results for this method yet
getFullRowCount()
No description for this method yet
No results for this method yet
getRecord()
No description for this method yet
No results for this method yet
getRecords()
No description for this method yet
No results for this method yet
getCollectionParentBuckets()
No description for this method yet
No results for this method yet
getCollectionChildBuckets()
No description for this method yet
No results for this method yet
toSetValuesMap()
No description for this method yet
No results for this method yet
hasAttribute()
No description for this method yet
No results for this method yet
getAttribute()
No description for this method yet
No results for this method yet
getLabel()
No description for this method yet
No results for this method yet
getLabelP()
No description for this method yet
No results for this method yet
getIntId()
No description for this method yet
No results for this method yet
getBucketName()
No description for this method yet
No results for this method yet
getCollectionBucketName()
No description for this method yet
No results for this method yet
getSlotNames()
No description for this method yet
No results for this method yet
getSlots()
No description for this method yet
No results for this method yet
getSlotTypes()
No description for this method yet
No results for this method yet
getSlotObject()
No description for this method yet
No results for this method yet
getSearchGroup()
No description for this method yet
No results for this method yet
getSlotDefinition()
No description for this method yet
No results for this method yet
getDisplayField()
No description for this method yet
No results for this method yet
getRecordDisplayValue()
No description for this method yet
No results for this method yet
getDisplayValue()
No description for this method yet
No results for this method yet
unloadToJSON()
No description for this method yet
No results for this method yet
rowToJSON()
No description for this method yet
No results for this method yet
rowsToJSON()
No description for this method yet
No results for this method yet
toJSON()
No description for this method yet
No results for this method yet
toRecordIntIds()
No description for this method yet
No results for this method yet
toCRC()
No description for this method yet
No results for this method yet
lock()
No description for this method yet
No results for this method yet
unlock()
No description for this method yet
No results for this method yet
getClientMessages()
No description for this method yet
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