Method | Prototype | Description |
Array | new Array(...):array | Array constructor. |
concat | concat(...):array | Return array with args appended. |
every | every(callback:function) | Returns true if every value in array satisfies the test. |
fill | fill(value:any, start:number=0, end:number=-1):array | Fill an array with values. |
filter | filter(callback:function, this:object=void):array | Return a filtered array. |
find | find(callback:function) | Returns the value of the first element in the array that satisfies the test. |
findIndex | findIndex(callback:function) | Returns the index of the first element in the array that satisfies the test. |
forEach | forEach(callback:function, this:object=void):void | Invoke function with each item in object. |
includes | includes(val:any) | Returns true if array contains value. |
indexOf | indexOf(str:any, startIdx:number=0):number | Return index of first occurrance in array. |
isArray | isArray(val:any):boolean | True if val array. |
join | join(sep:string=''):string | Return elements joined by char. |
lastIndexOf | lastIndexOf(val:any, start:number=0):number | Return index of last occurence in array. |
map | map(callback:function, this:object=void):array | Creates a new array with the results of calling a provided function on every element in this array. |
pop | pop() | Remove and return last element of array. |
push | push(val:any, ...):number | Push one or more elements onto array and return size. |
reverse | reverse():array | Reverse order of all elements in an array. |
shift | shift() | Remove first element and shift downwards. |
sizeOf | sizeOf():number | Return size of array. |
slice | slice(start:number, end:number=void):array | Return sub-array. |
some | some(callback:function, this:object=void):boolean | Return true if function returns true some element. |
sort | sort(options:function|object=void):array | Sort an array. |
splice | splice(start:number, howmany:number=void, ...):array | Change the content of an array, adding new elements while removing old elements. |
unshift | unshift(...):number | Add new elements to start of array and return size. |
Method | Prototype | Description |
CData | new CData(options:string|object=void, inits:object=undefined):userobj | Create a new struct or map/array of structs.The 2nd arg is used for function option parsing and will report errors at the callers file:line |
conf | conf(options:object|string=void) | Configure options for c-data. |
get | get(key:string|number|object=null, field:string=void) | Get struct/map/array value. |
incr | incr(key:string|number|object|null, field:object|string, value:number):number | Increment a numeric field: returns the new value. |
info | info():object | Return info for data. |
names | names():array | Return keys for map. |
set | set(key:string|number|object|null, field:object|string, value:any=void) | Set a struct/map/array value. |
unset | unset(key:string|number|object) | Remove entry from map/array. |
Enum commands. Note: Enum() is a shortcut for Enum.add().
Method | Prototype | Description |
add | add(options:object|string, fields:array|string) | Create a new enum: value of items same as in fieldconf. |
conf | conf(enum:string, options:object|string=void) | Configure options for enum. |
fieldconf | fieldconf(enum:string, field:string, options:object|string=void) | Configure options for fields. |
find | find(enum:string, intValue:number):string | Find item with given value in enum. |
get | get(enum:string):object | Return enum definition. |
names | names(enum:string=void):array | Return name list of all enums, or items within one enum. |
remove | remove(enum:string) | Remove an enum. |
value | value(enum:string, item:string):number | Return value for given enum item. |
Struct commands. Note: Struct() is a shortcut for Struct.add().
Method | Prototype | Description |
add | add(options:object|string, fields:array|string) | Create a struct: field values same as in fieldconf. |
conf | conf(struct:string, options:object|string=void) | Configure options for struct. |
fieldconf | fieldconf(struct:string, field:string, options:object|string=void) | Configure options for fields. |
get | get(struct, options:object=void):object | Return the struct definition. |
names | names(struct:string=void):array | Return name list of all structs, or fields for one struct. |
remove | remove(name:string) | Remove a struct. |
schema | schema():string | Return database schema for struct. |
Type commands. Note: Type() is a shortcut for Type.conf().
Method | Prototype | Description |
clearInterval | clearInterval(id:number):void | Delete an event (created with setInterval/setTimeout). |
info | info(id:number):object | Return info for the given event id. |
names | names():array | Return list event ids (created with setTimeout/setInterval). |
setInterval | setInterval(callback:function, millisecs:number):number | Setup recurring function to run every given millisecs. |
setTimeout | setTimeout(callback:function, millisecs:number):number | Setup function to run after given millisecs. |
update | update(options:number|object=void):number | Service all events, eg. setInterval/setTimeout. Returns the number of events processed. Events are processed until minTime (in milliseconds) is exceeded, or forever if -1.
The default minTime is 0, meaning return as soon as no events can be processed. A positive mintime will result in sleeps between event checks. |
Method | Prototype | Description |
atime | atime(file:string):number | Return file Jsi_Access time. |
chdir | chdir(file:string) | Change current directory. |
chmod | chmod(file:string, mode:number) | Set file permissions. |
copy | copy(src:string, dest:string, force:boolean=false) | Copy a file to destination. Directories are not handled.
The third argument if given is a boolean force value which if true allows overwrite of an existing file. |
dirname | dirname(file:string):string | Return directory path. |
executable | executable(file:string):boolean | Return true if file is executable. |
exists | exists(file:string):boolean | Return true if file exists. |
extension | extension(file:string):string | Return file extension. |
glob | glob(pattern:regexp|string|null='*', options:function|object|null=void):array | Return list of files in dir with optional pattern match. With no arguments (or null) returns all files/directories in current directory.
The first argument can be a pattern (either a glob or regexp) of the files to return.
When the second argument is a function, it is called with each path, and filter on false.
Otherwise second arugment must be a set of options. |
isdir | isdir(file:string):boolean | Return true if file is a directory. |
isfile | isfile(file:string):boolean | Return true if file is a normal file. |
isrelative | isrelative(file:string):boolean | Return true if file path is relative. |
join | join(path:string, path:string):string | Join two file realpaths, or just second if an absolute path. |
link | link(src:string, dest:string, ishard:boolean=false) | Link a file. The second argument is the destination file to be created. If a third bool argument is true, a hard link is created. |
lstat | lstat(file:string):object | Return status info for file. |
mkdir | mkdir(file:string) | Create a directory. |
mtime | mtime(file:string):number | Return file modified time. |
owned | owned(file:string):boolean | Return true if file is owned by user. |
pwd | pwd():string | Return current directory. |
read | read(file:string, mode:string='rb'):string | Read a file. |
readable | readable(file:string):boolean | Return true if file is readable. |
readlink | readlink(file:string):string | Read file link destination. |
realpath | realpath(file:string):string | Return absolute file name minus .., ./ etc. |
remove | remove(file:string, force:boolean=false) | Delete a file or direcotry. |
rename | rename(src:string, dest:string, force:boolean=false) | Rename a file, with possible overwrite. |
rootname | rootname(file:string):string | Return file name minus extension. |
size | size(file:string):number | Return size for file. |
stat | stat(file:string):object | Return status info for file. |
tail | tail(file:string):string | Return file name minus dirname. |
tempfile | tempfile(file:string) | Create a temp file. |
truncate | truncate(file:string, size:number) | Truncate file. |
type | type(file:string):string | Return type of file. |
writable | writable(file:string):boolean | Return true if file is writable. |
write | write(file:string, str:string, mode:string='wb+'):number | Write a file. |
Option | Type | Description | Flags |
dir | STRING | The start directory: this path will not be prepended to results. | |
maxDepth | INT | Maximum directory depth to recurse into. | |
maxDiscard | INT | Maximum number of items to discard before giving up. | |
dirFilter | FUNC | Filter function for directories, returning false to discard. @function(dir:string) | |
filter | FUNC | Filter function to call with each file, returning false to discard. @function(file:string) | |
limit | INT | The maximum number of results to return/count. | |
noTypes | STRKEY | Filter files to exclude these "types". | |
prefix | STRKEY | String prefix to add to each file in list. | |
recurse | BOOL | Recurse into sub-directories. | |
retCount | BOOL | Return only the count of matches. | |
tails | BOOL | Returned only tail of path. | |
types | STRKEY | Filter files to include type: one or more of chars 'fdlpsbc' for file, directory, link, etc. | |
Method | Prototype | Description |
argv0 | argv0():string|void | Return initial start script file name. |
cmds | cmds(val:string|regexp='*', options:object=void):array|object | Return details or list of matching commands. |
completions | completions(str:string, start:number=0, end:number=void):array | Return command completions on portion of string from start to end. |
data | data(val:string|regexp|object=void):array | Return list of matching data (non-functions). Like info.vars(), but does not return function values. |
error | error():object | Return file and line number of error (used inside catch). |
event | event(id:number=void):array|object | List events or info for 1 event (setTimeout/setInterval). With no args, returns list of all outstanding events. With one arg, returns infofor the given event id. |
execZip | execZip():string|void | If executing a .zip file, return file name. |
executable | executable():string | Return name of executable. |
files | files():array | Return list of all sourced files. |
funcs | funcs(string|regexp|object=void):array|object | Return details or list of matching functions. |
interp | interp(interp:userobj=void):object | Return info on given or current interp. |
isMain | isMain():boolean | Return true if current script was the main script invoked from command-line. |
keywords | keywords():array | Return list of reserved jsi keywords. |
level | level(level:number=void):number|array|object | Return current level or details of a call-stack frame. With no arg, returns the number of the current stack frame level.
Otherwise returns details on the specified level.
The topmost level is 1, and 0 is the current level, and a negative level translates as relative to the current level. |
lookup | lookup(name:string) | Given string name, lookup and return value (eg. function). |
methods | methods(val:string|regexp):array|object | Return functions and commands. |
named | named(name:string=void):array|userobj | Returns command names for builtin Objects (eg. 'File', 'Interp'), sub-Object names, or the named object. |
options | options(ctype:boolean=false):array | Return Option type name, or with true the C type). |
package | package(pkgName:string):object|null | Return info about provided package if exists, else null. |
platform | platform():object | N/A. Returns general platform information for JSI. |
script | script(func:function|regexp=void):string|array|void | Get current script file name, or file containing function. |
scriptDir | scriptDir():string|void | Get directory of current script. |
vars | vars(val:string|regexp|object=void):array|object | Return details or list of matching variables. Returns all values, data or function. |
version | version(bool:boolean=false):number|object | JSI version as: with bool not true a double, otherwise an object. |
Method | Prototype | Description |
Interp | new Interp(options:object=void):userobj | Create a new interp. |
alias | alias(name:string=void, func:function|null=void, args:array|null=void) | Set/get global alias bindings for command in an interp. With 0 args, returns list of all aliases in interp.
With 1 arg returns func for given alias name.
With 2 args, returns args for given alias name (args must be null).
With 3 args, create/update an alias for func and args. Delete an alias by creating it with null for both func and args. |
call | call(funcName:string, args:string|array, async:boolean=false) | Call named function in subinterp. Invoke function in sub-interp with arguments.
Since interps are not allowed to share objects, data is automatically cleansed by encoding/decoding to/from JSON if required.
Unless an 'async' parameter of true is given, we wait until the sub-interp is idle, make the call, and return the result. Otherwise the call is acyncronous. |
conf | conf(options:string|object=void) | Configure option(s). |
eval | eval(js:string, async:boolean=false) | Interpret script within sub-interp. When the 'async' option is used on a threaded interp, the script is queued as an Event. |
info | info():object | Returns internal statistics about interp. |
send | send(msg:any) | Enqueue message onto a sub-interps recvCallback handler. Add messages to queue to be processed by the 'recvCallback' interp option. |
source | source(file:string, async:boolean=false) | Interpret file within sub-interp. When the 'async' option is used on a threaded interp, the script is queued as an Event. |
uplevel | uplevel(js:string, level:number=0) | Interpret code at the given stack level: see Info.level(). The level argument is as returned by Info.level(). Not supported with threads. |
value | value(var:string, level:number=0) | Lookup value of variable at stack level: see Info.level(). |
Option | Type | Description | Flags |
args | ARRAY | The console.arguments for interp. | initOnly |
asserts | BOOL | Enable assert. | |
assertMode | STRKEY | Action upon assert failure. (one of: throw, log, puts) | |
autoFiles | ARRAY | File(s) to source for loading Jsi_Auto to handle unknown commands. | |
busyCallback | CUSTOM | Command in parent interp (or noOp) to periodically call. | |
busyInterval | INT | Call busyCallback command after this many op-code evals (100000). | |
coverage | BOOL | On exit generate detailed code coverage for function calls (with profile). | |
debugOpts | options | Options for debugging. | |
hasOpenSSL | BOOL | Is SSL available in WebSocket. | initOnly |
historyFile | STRKEY | In interactive mode, file to use for history (~/.jsish_history). | initOnly |
isSafe | BOOL | Is this a safe interp (ie. with limited or no file access). | initOnly |
jsppChars | STRKEY | Line preprocessor when sourcing files. Line starts with first char, and either ends with it, or matches string. | |
jsppCallback | FUNC | Command to preprocess lines that match jsppChars. Call func(interpName:string, opCnt:number). | |
lockTimeout | INT | Thread time-out for mutex lock acquires (milliseconds). | |
logOpts | options | Options for log output to add file/line/time. | |
maxDepth | INT | Depth limit of recursive function calls (1000). | |
maxIncDepth | INT | Maximum allowed source/require nesting depth (50). | |
maxInterpDepth | INT | Maximum nested subinterp create depth (10). | |
maxUserObjs | INT | Maximum number of 'new' object calls, eg. File, RegExp, etc. | |
maxOpCnt | INT | Execution limit for op-code evaluation. | initOnly |
memDebug | INT | Memory debugging level: 1=summary, 2=detail. | |
name | STRKEY | Optional text name for this interp. | |
noAutoLoad | BOOL | Disable autoload. | |
noConfig | BOOL | Disable use of Interp.conf to change options after create. | initOnly |
noInput | BOOL | Disable use of console.input(). | |
noLoad | BOOL | Disable load of shared libs. | |
noNetwork | BOOL | Disable new Socket/WebSocket, or load of builtin MySql. | |
noStderr | BOOL | Make puts, log, assert, etc use stdout. | |
noSubInterps | BOOL | Disallow sub-interp creation. | |
onComplete | FUNC | Function to return commands completions for interactive mode. Default uses Info.completions . @function(prefix:string, start:number, end:number) | |
onEval | FUNC | Function to get control for interactive evals. @function(cmd:string) | |
onExit | FUNC | Command to call in parent on exit, returns true to continue. @function() | initOnly |
opTrace | INT | Set debugging level for OPCODE execution. | |
pkgDirs | ARRAY | list of library directories for require() to search. | |
profile | BOOL | On exit generate profile of function calls. | |
recvCallback | CUSTOM | Command to recv 'send' msgs from parent interp. | |
retValue | VALUE | Return value from last eval. | readOnly |
safeReadDirs | ARRAY | In safe mode, files/dirs to allow reads from. | initOnly |
safeWriteDirs | ARRAY | In safe mode, files/dirs to allow writes to. | initOnly |
safeExecPattern | STRKEY | In safe mode, regexp pattern allow exec of commands. | initOnly |
scriptStr | STRKEY | Interp init script string. | initOnly |
scriptFile | STRING | Interp init script file. | |
stdinStr | STRING | String to use as stdin for console.input(). | |
stdoutStr | STRING | String to collect stdout for puts(). | |
strict | BOOL | Globally enable strict: same as 'use strict' in main program. | |
subOpts | options | Infrequently used sub-options. | |
subthread | BOOL | Create a threaded Interp. | initOnly |
traceCall | ARRAY | Trace commands. (zero or more of: funcs, cmds, new, return, args, notrunc, noparent, full, before) | |
tracePuts | BOOL | Trace puts by making it use logOpts. | |
typeCheck | ARRAY | Type-check control options. (zero or more of: parse, run, all, error, strict, noundef, nowith, funcsig) | |
typeWarnMax | INT | Type checking is silently disabled after this many warnings (50). | |
unitTest | UINT | Unit test control bits: 1=subst ;;, 2=Puts with file:line prefix. | |
Method | Prototype | Description |
abs | abs(num:number):number | Returns the absolute value of x. |
acos | acos(num:number):number | Returns the arccosine of x, in radians. |
asin | asin(num:number):number | Returns the arcsine of x, in radians. |
atan | atan(num:number):number | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians. |
atan2 | atan2(x:number, y:number):number | Returns the arctangent of the quotient of its arguments. |
ceil | ceil(num:number):number | Returns x, rounded upwards to the nearest integer. |
cos | cos(num:number):number | Returns the cosine of x (x is in radians). |
exp | exp(num:number):number | Returns the value of Ex. |
floor | floor(num:number):number | Returns x, rounded downwards to the nearest integer. |
log | log(num:number):number | Returns the natural logarithm (base E) of x. |
max | max(x:number, y:number, ...):number | Returns the number with the highest value. |
min | min(x:number, y:number, ...):number | Returns the number with the lowest value. |
pow | pow(x:number, y:number):number | Returns the value of x to the power of y. |
random | random():number | Returns a random number between 0 and 1. |
round | round(num:number):number | Rounds x to the nearest integer. |
sin | sin(num:number):number | Returns the sine of x (x is in radians). |
sqrt | sqrt(num:number):number | Returns the square root of x. |
tan | tan(num:number):number | Returns the tangent of an angle. |
Method | Prototype | Description |
MySql | new MySql(options:object=void):userobj | Create a new db connection to a MySql database:. |
affectedRows | affectedRows():number | Return affected rows. |
complete | complete(sql:string):boolean | Return true if sql is complete. |
conf | conf(options:string|object=void) | Configure options. |
errorNo | errorNo():number | Return error code returned by most recent call to mysql3_exec(). |
errorState | errorState():string | Return the mysql error state str. |
eval | eval(sql:string):number | Run sql commands without input/output. |
exists | exists(sql:string):boolean | Execute sql, and return true if there is at least one result value. |
info | info():object | Return info about last query. |
lastQuery | lastQuery():string | Return info string about most recently executed statement. |
lastRowid | lastRowid():number | Return rowid of last insert. |
onecolumn | onecolumn(sql:string) | Execute sql, and return a single value. |
ping | ping(noError:boolean=false):number | Ping connection. |
query | query(sql:string, options:function|object=void) | Run sql query with input and/or outputs.. |
reconnect | reconnect():void | Reconnect with current settings. |
reset | reset():number | Reset connection. |
Option | Type | Description | Flags |
callback | FUNC | Function to call with each row result. @function(values:object) | |
headers | BOOL | First row returned contains column labels. | |
limit | INT | Maximum number of returned values. | |
mapundef | BOOL | In variable binds, map an 'undefined' var to null. | |
maxString | INT | If not using prefetch, the maximum string value size (0=8K). | |
mode | STRKEY | Set output mode of returned data. (one of: rows, arrays, array1d, list, column, json, json2, html, csv, insert, line, tabs, none) | |
nocache | BOOL | Query is not to be cached. | |
noNamedParams | BOOL | Disable translating sql to support named params. | |
nullvalue | STRKEY | Null string output (for non-json mode). | |
paramVar | ARRAY | Array var to use for parameters. | |
prefetch | BOOL | Let client library cache entire results. | |
separator | STRKEY | Separator string (for csv and text mode). | |
table | STRKEY | Table name for mode=insert. | |
typeCheck | STRKEY | Type check mode (error). (one of: convert, error, warn, disable) | |
values | ARRAY | Values for ? bind parameters. | |
varName | STRKEY | String name of array var for ? bind parameters. | |
width | CUSTOM | In column mode, set column widths. | |
Option | Type | Description | Flags |
callback | FUNC | Function to call with each row result. @function(values:object) | |
headers | BOOL | First row returned contains column labels. | |
limit | INT | Maximum number of returned values. | |
mapundef | BOOL | In variable binds, map an 'undefined' var to null. | |
maxString | INT | If not using prefetch, the maximum string value size (0=8K). | |
mode | STRKEY | Set output mode of returned data. (one of: rows, arrays, array1d, list, column, json, json2, html, csv, insert, line, tabs, none) | |
nocache | BOOL | Query is not to be cached. | |
noNamedParams | BOOL | Disable translating sql to support named params. | |
nullvalue | STRKEY | Null string output (for non-json mode). | |
paramVar | ARRAY | Array var to use for parameters. | |
prefetch | BOOL | Let client library cache entire results. | |
separator | STRKEY | Separator string (for csv and text mode). | |
table | STRKEY | Table name for mode=insert. | |
typeCheck | STRKEY | Type check mode (error). (one of: convert, error, warn, disable) | |
values | ARRAY | Values for ? bind parameters. | |
varName | STRKEY | String name of array var for ? bind parameters. | |
width | CUSTOM | In column mode, set column widths. | |
Method | Prototype | Description |
Object | new Object(val:object|null=void):object | Object constructor. |
create | create(proto:null|object, properties:object=void):object | Create a new object with prototype object and properties. |
getPrototypeOf | getPrototypeOf(name:object):object | Return prototype of an object. |
hasOwnProperty | hasOwnProperty(name:string):boolean | Returns a true if object has the specified property. |
is | is(value1, value2):boolean | Tests if two values are equal. |
isPrototypeOf | isPrototypeOf(name):boolean | Tests for an object in another object's prototype chain. |
keys | keys(obj:object=void):array | Return the keys of an object or array. |
merge | merge(obj:object):object | Return new object containing merged values. |
propertyIsEnumerable | propertyIsEnumerable(name):boolean | Determine if a property is enumerable. |
setPrototypeOf | setPrototypeOf(name:object, value:object) | Set prototype of an object. |
toLocaleString | toLocaleString(quote:boolean=false):string | Convert to string. |
toString | toString(quote:boolean=false):string | Convert to string. |
valueOf | valueOf() | Returns primitive value. |
Option | Type | Description | Flags |
address | STRING | Client destination address (127.0.0.0). | initOnly |
broadcast | BOOL | Enable broadcast. | initOnly |
client | BOOL | Enable client mode. | initOnly |
connectCnt | INT | Counter for number of active connections. | readOnly |
createLast | TIME_T | Time of last create. | readOnly |
debug | INT | Debugging level. | |
echo | BOOL | LogInfo outputs all socket Send/Recv messages. | |
interface | STRING | Interface for server to listen on, eg. 'eth0' or 'lo'. | initOnly |
keepalive | BOOL | Enable keepalive. | initOnly |
maxConnects | INT | In server mode, max number of client connections accepted. | |
mcastAddMember | STRING | Multicast add membership: address/interface ('127.0.0.1/0.0.0.0'). | initOnly |
mcastInterface | STRING | Multicast interface address. | initOnly |
mcastNoLoop | BOOL | Multicast loopback disable. | initOnly |
mcastTtl | INT | Multicast TTL. | initOnly |
noAsync | BOOL | Send is not async. | initOnly |
noUpdate | BOOL | Stop processing update events (eg. to exit). | |
onClose | FUNC | Function to call when connection closes. @function(s:userobj|null, id:number) | |
onCloseLast | FUNC | Function to call when last connection closes. On object delete arg is null. @function(s:userobj|null) | |
noConfig | BOOL | Disable use of Socket.conf to change options after create. | initOnly |
onOpen | FUNC | Function to call when connection opens. @function(s:userobj, info:object) | |
onRecv | FUNC | Function to call with recieved data. @function(s:userobj, id:number, data:string) | |
port | INT | Port for client dest or server listen. | initOnly |
quiet | BOOL | Suppress info messages. | initOnly |
recvTimeout | UINT64 | Timeout for receive, in microseconds. | initOnly |
sendTimeout | UINT64 | Timeout for send, in microseconds. | initOnly |
srcAddress | STRING | Client source address. | initOnly |
srcPort | INT | Client source port. | initOnly |
startTime | TIME_T | Time of start. | readOnly |
stats | options | Statistical data. | readOnly |
timeout | NUMBER | Timeout value in seconds (0.5). | initOnly |
tos | INT8 | Type-Of-Service value. | initOnly |
ttl | INT | Time-To-Live value. | initOnly |
udp | BOOL | Protocol is udp. | initOnly |
Method | Prototype | Description |
Sqlite | new Sqlite(file:string=void, options:object=void):userobj | Create a new db connection to the named file or :memory:. |
backup | backup(file:string, dbname:string='main'):void | Backup db to file. Open or create a database file named FILENAME.
Transfer the content of local database DATABASE (default: 'main') into the FILENAME database. |
collate | collate(name:string, callback:function):void | Create new SQL collation command. |
complete | complete(sql:string):boolean | Return true if sql is complete. |
conf | conf(options:string|object=void) | Configure options. |
eval | eval(sql:string):number | Run sql commands without input/output. Supports multiple semicolon seperated commands.
Variable binding is NOT performed, results are discarded, and returns sqlite3_changes() |
exists | exists(sql:string):boolean | Execute sql, and return true if there is at least one result value. |
filename | filename(name:string='main'):string | Return filename for named or all attached databases. |
func | func(name:string, callback:function, numArgs:number=void):void | Register a new function with database. |
import | import(table:string, file:string, options:object=void):number | Import data from file into table . Import data from a file into table. SqlOptions include the 'separator' to use, which defaults to commas for csv, or tabs otherwise.
If a column contains a null string, or the value of 'nullvalue', a null is inserted for the column.
A 'conflict' is one of the sqlite conflict algorithms: rollback, abort, fail, ignore, replace
On success, return the number of lines processed, not necessarily same as 'changeCnt' due to the conflict algorithm selected. |
interrupt | interrupt():void | Interrupt in progress statement. |
onecolumn | onecolumn(sql:string) | Execute sql, and return a single value. |
query | query(sql:string, options:function|object=void) | Evaluate an sql query with bindings. Return values in formatted as JSON, HTML, etc. , optionally calling function with a result object |
restore | restore(file:string, dbname:string):void | Restore db from file (default db is 'main'). db.restore(FILENAME, ?,DATABASE? )
Open a database file named FILENAME. Transfer the content of FILENAME into the local database DATABASE (default: 'main'). |
transaction | transaction(callback:function, type:string=void):void | Call function inside db tranasaction. Type is: 'deferred', 'exclusive', 'immediate'. Start a new transaction (if we are not already in the midst of a transaction) and execute the JS function FUNC.
After FUNC completes, either commit the transaction or roll it back if FUNC throws an exception.
Or if no new transation was started, do nothing. pass the exception on up the stack. |
Option | Type | Description | Flags |
bindWarn | BOOL | Treat failed variable binds as a warning. | initOnly |
changeCnt | INT | The number of rows modified, inserted, or deleted by last command. | |
changeCntAll | INT | Total number of rows modified, inserted, or deleted since db opened. | |
debug | ARRAY | Enable debug trace for various operations. (zero or more of: eval, delete, prepare, step) | |
echo | BOOL | LogInfo outputs the string value of every query and eval. | |
errCnt | INT | Count of errors in script callbacks. | readOnly |
errorCode | INT | Numeric error code returned by the most recent call to sqlite3_exec. | |
forceInt | BOOL | Bind float as int if possible. | |
lastInsertId | UINT64 | The rowid of last insert. | |
load | BOOL | Extensions can be loaded. | |
mutex | STRKEY | Mutex type to use. (one of: default, none, full) | initOnly |
name | DSTRING | Optional name field. | |
noConfig | BOOL | Disable use of Sqlite.conf to change options after create. | initOnly |
noCreate | BOOL | Database is must already exist (false). | initOnly |
onAuth | FUNC | Function to call for auth. @function(db:userobj, code:string, descr1:string, decr2:string, dbname:string, trigname:string) | |
onBusy | FUNC | Function to call when busy. @function(db:userobj, tries:number) | |
onCommit | FUNC | Function to call on commit. @function(db:userobj) | |
onNeedCollate | FUNC | Function to call for collation. @function(db:userobj, name:string) | |
onProfile | FUNC | Function to call for profile. @function(db:userobj, sql:string, time:number) | |
onProgress | FUNC | Function to call for progress: progressSteps must be >0. @function(db:userobj) | |
onRollback | FUNC | Function to call for rollback. @function(db:userobj) | |
onTrace | FUNC | Function to call for trace. @function(db:userobj, sql:string) | |
onUpdate | FUNC | Function to call for update. @function(db:userobj, op:string, dbname:string, table:string, rowid:number) | |
onWalHook | FUNC | Function to call for WAL. @function(db:userobj, dbname:string, entry:number) | |
progressSteps | UINT | Number of steps between calling onProgress: 0 is disabled. | |
queryOpts | options | Default options for to use with query(). | |
readonly | BOOL | Database opened in readonly mode. | initOnly |
sortCnt | INT | Number of sorts in most recent operation. | readOnly |
stepCnt | INT | Number of steps in most recent operation. | readOnly |
stmtCacheCnt | INT | Current size of compiled statement cache. | readOnly |
stmtCacheMax | INT | Max cache size for compiled statements. | |
timeout | INT | Amount of time to wait when file is locked, in ms. | |
version | OBJ | Sqlite version info. | readOnly |
vfs | STRING | VFS to use. | initOnly |
Option | Type | Description | Flags |
callback | FUNC | Function to call with each row result. @function(values:object) | |
cdata | STRKEY | Name of Cdata array object to use. | |
headers | BOOL | First row returned contains column labels. | |
limit | INT | Maximum number of returned values. | |
mapundef | BOOL | In variable bind, map an 'undefined' var to null. | |
mode | STRKEY | Set output mode of returned data. (one of: rows, arrays, array1d, list, column, json, json2, html, csv, insert, line, tabs, none) | |
nocache | BOOL | Query is not to be cached. | |
nullvalue | STRKEY | Null string output (for non js/json mode). | |
retChanged | BOOL | Query returns value of sqlite3_changed(). | |
separator | STRKEY | Separator string (for csv and text mode). | |
typeCheck | STRKEY | Type check mode (warn). (one of: convert, warn, error, disable) | |
table | STRKEY | Table name for mode=insert. | |
values | ARRAY | Values for ? bind parameters. | |
varName | STRKEY | Array var for ? bind parameters. | |
width | CUSTOM | In column mode, set column widths. | |
Option | Type | Description | Flags |
callback | FUNC | Function to call with each row result. @function(values:object) | |
cdata | STRKEY | Name of Cdata array object to use. | |
headers | BOOL | First row returned contains column labels. | |
limit | INT | Maximum number of returned values. | |
mapundef | BOOL | In variable bind, map an 'undefined' var to null. | |
mode | STRKEY | Set output mode of returned data. (one of: rows, arrays, array1d, list, column, json, json2, html, csv, insert, line, tabs, none) | |
nocache | BOOL | Query is not to be cached. | |
nullvalue | STRKEY | Null string output (for non js/json mode). | |
retChanged | BOOL | Query returns value of sqlite3_changed(). | |
separator | STRKEY | Separator string (for csv and text mode). | |
typeCheck | STRKEY | Type check mode (warn). (one of: convert, warn, error, disable) | |
table | STRKEY | Table name for mode=insert. | |
values | ARRAY | Values for ? bind parameters. | |
varName | STRKEY | Array var for ? bind parameters. | |
width | CUSTOM | In column mode, set column widths. | |
Method | Prototype | Description |
String | new String(str):string | String constructor. |
charAt | charAt(index:number):string | Return char at index. |
charCodeAt | charCodeAt(index:number):number | Return char code at index. |
concat | concat(str:string, ...):string | Append one or more strings. |
indexOf | indexOf(str:string, start:number):number | Return index of char. |
lastIndexOf | lastIndexOf(str:string, start:number):number | Return index of last char. |
map | map(strMap:array, nocase:boolean=false):string | Replaces characters in string based on the key-value pairs in strMap. |
match | match(pattern:regexp|string):array|null | Return array of matches. |
repeat | repeat(count:number):string | Return count copies of string. |
replace | replace(pattern:regexp|string, replace:string|function):string | Regex/string replacement. If the replace argument is a function, it is called with match,p1,p2,...,offset,string. If called function is known to have 1 argument, it is called with just the match. |
search | search(pattern:regexp|string):number | Return index of first char matching pattern. |
slice | slice(start:number, end:number):string | Return section of string. |
split | split(char:string|null=void):array | Split on char and return Array: null removes empty elements. |
substr | substr(start:number, length:number):string | Return substring. |
substring | substring(start:number, end:number):string | Return substring. |
toLocaleLowerCase | toLocaleLowerCase():string | Lower case. |
toLocaleUpperCase | toLocaleUpperCase():string | Upper case. |
toLowerCase | toLowerCase():string | Return lower cased string. |
toTitle | toTitle(chars:string):string | Make first char upper case. |
toUpperCase | toUpperCase():string | Return upper cased string. |
trim | trim(chars:string):string | Trim chars. |
trimLeft | trimLeft(chars:string):string | Trim chars from left. |
trimRight | trimRight(chars:string):string | Trim chars from right. |
Builtin system commands. All methods are exported as global.
Method | Prototype | Description |
assert | assert(expr:boolean|number|function, msg:string=void, options:object=void):void | Throw or output msg if expr is false. Assert does nothing by default, but can be enabled with "use assert" or setting Interp.asserts. |
clearInterval | clearInterval(id:number):void | Delete event id returned from setInterval/setTimeout/info.events(). |
decodeURI | decodeURI(val:string):string | Decode an HTTP URL. |
encodeURI | encodeURI(val:string):string | Encode an HTTP URL. |
exec | exec(val:string, options:string|object=void) | Execute an OS command. If the command ends with '&', set the 'bg' option to true.
The second argument can be a string, which is the same as setting the 'inputStr' option.
By default, returns the string output, unless the 'bg', 'inputStr', 'retCode' or 'retAll' options are used |
exit | exit(code:number=0):void | Exit the current interpreter. |
format | format(format:string, ...):string | Printf style formatting: adds %q and %S. |
isFinite | isFinite(val):boolean | Return true if is a finite number. |
isMain | isMain():boolean | Return true if current script was the main script invoked from command-line. |
isNaN | isNaN(val):boolean | Return true if not a number. |
load | load(shlib:string):void | Load a shared executable and invoke its _Init call. |
log | log(val, ...):void | Same as puts, but includes file:line. |
noOp | noOp() | A No-Op. A zero overhead command call that is useful for debugging. |
parseFloat | parseFloat(val):number | Convert string to a double. |
parseInt | parseInt(val:any, base:number=10):number | Convert string to an integer. |
parseOpts | parseOpts(self:object|userobj, options:object, conf:object|null|undefined) | Parse options. |
printf | printf(format:string, ...):void | Formatted output to stdout. |
provide | provide(name:string|function=void, version:number|string=1.0):void | Provide a package for use with require. Default is the file tail-rootname. |
puts | puts(val, ...):void | Output one or more values to stdout. Each argument is quoted. Use Interp.logOpts to control source line and/or timestamps output. |
quote | quote(val:string):string | Return quoted string. |
require | require(name:string=void, version:number|string=1):number|array|object | Load/query packages. With no arguments, returns the list of all loaded packages.
With one argument, loads the package (if necessary) and returns its version.
With two arguments, returns object containing: version, loadFile, func.
An error is thrown if requested version is greater than actual version. |
runModule | runModule(cmd:string|function=void, conf:array=undefined) | Invoke named module. If name is empty, uses file basename. If isMain and no args givine parses console.args. |
setInterval | setInterval(callback:function, ms:number):number | Setup recurring function to run every given millisecs. |
setTimeout | setTimeout(callback:function, ms:number):number | Setup function to run after given millisecs. |
sleep | sleep(secs:number=1.0):void | sleep for N milliseconds, minimum .001. |
source | source(val:string|array, options:object=void):void | Load and evaluate source files. |
strftime | strftime(num:number=null, options:string|object=void):string | Format numeric time (in ms) to a string. Null or no value will use current time. |
strptime | strptime(val:string=void, options:string|object=void):number | Parse time from string and return ms time since 1970-01-01 in UTC, or NaN. |
unload | unload(shlib:string):void | Unload a shared executable and invoke its _Done call. |
update | update(options:number|object=void):number | Service all events, eg. setInterval/setTimeout. Returns the number of events processed. Events are processed until minTime (in milliseconds) is exceeded, or forever if -1.
The default minTime is 0, meaning return as soon as no events can be processed. A positive mintime will result in sleeps between event checks. |
Method | Prototype | Description |
base64 | base64(val:string, decode:boolean=false):string | Base64 encode/decode a string. |
crc32 | crc32(val:string, crcSeed=0):number | Calculate 32-bit CRC. |
decrypt | decrypt(val:string, key:string):string | Decrypt data using BTEA encryption. Keys that are not 16 bytes use the MD5 hash of the key. |
encrypt | encrypt(val:string, key:string):string | Encrypt data using BTEA encryption. Keys that are not 16 bytes use the MD5 hash of the key. |
fromCharCode | fromCharCode(code:number):string | Return char with given character code. |
getenv | getenv(name:string=void):string|object|void | Get one or all environment. |
getpid | getpid(parent:boolean=false):number | Get process/parent id. |
hash | hash(val:string, options|object=void):string | Return hash (default SHA256) of string/file. |
hexStr | hexStr(val:string, decode:boolean=false):string | Hex encode/decode a string. |
setenv | setenv(name:string, value:string=void) | Set/get an environment var. |
times | times(callback:function, count:number=1):number | Call function count times and return execution time in microseconds. |
verConvert | verConvert(ver:string|number, zeroTrim:number=0):number|string|null | Convert a version to/from a string/number, or return null if not a version. For string output zeroTrim says how many trailing .0 to trim (0-2). |
Method | Prototype | Description |
conf | conf(mount:string, string|options:object|string=void) | Configure mount. |
exec | exec(cmd:string) | Safe mode exec for VFS support cmds eg. fossil info/ls/cat. |
fileconf | fileconf(mount:string, path:string, options:string|object=void) | Configure file info which is same info as in fileList. |
list | list():array | Return list of all vfs mounts. |
mount | mount(type:string, file:string, param:object=void):string | Mount fossil file as given VFS type name, returning the mount point: frontend for vmount. |
type | type(type:string=void, options:object|null=void) | Set/get/delete VFS type name. |
unmount | unmount(mount:string):void | Unmount a VFS. |
vmount | vmount(options:object=void):string | Create and mount a VFS, returning the mount point. |
Method | Prototype | Description |
WebSocket | new WebSocket(options:object=void):userobj | Create websocket server/client object.Create a websocket server/client object. The server serves out pages to a web browser,
which can use javascript to upgrade connection to a bidirectional websocket. |
conf | conf(options:string|object=void) | Configure options. |
handler | handler(extension:string=void, cmd:string|function=void, arg:string|null=void, flags:number=0):string|array|function|void | Get/Set handler command for an extension. With no args, returns list of handlers. With one arg, returns value for that handler.
Otherwise, sets the handler. When cmd is a string, the call is via runModule([cmd], arg).
If a cmd is a function, it is called with a single arg: the file name. |
header | header(id:number, name:string=void):string|object|void | Get one or all input headers for connect id. |
idconf | idconf(id:number, options:string|object=void) | Configure options for connect id. |
ids | ids():array | Return list of ids. |
query | query(id:number, name:string=void):string|object|void | Get one or all query values for connect id. |
send | send(id:number, data:any):void | Send a websocket message to id. Send a message to one (or all connections if -1). If not already a string, msg is formatted as JSON prior to the send. |
status | status():object|void | Return libwebsocket server status. |
update | update():void | Service events for just this websocket. |
version | version():string | Runtime library version string. |
Option | Type | Description | Flags |
address | STRING | In client-mode the address to connect to (127.0.0.1). | |
bufferPwr2 | INT | Tune the recv/send buffer: value is a power of 2 in [0-20] (16). | |
client | BOOL | Run in client mode. | initOnly |
clientHost | STRKEY | Override host name for client. | |
clientOrigin | STRKEY | Override client origin (origin). | |
debug | INT | Set debug level. Setting this to 512 will turn on max libwebsocket log levels. | |
echo | BOOL | LogInfo outputs all websock Send/Recv messages. | |
formParams | STRKEY | Comma seperated list of upload form param names ('text,send,file,upload'). | readOnly |
extArgs | OBJ | Arguments for extension handlers. | initOnly |
extHandlers | BOOL | Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md. | initOnly |
getRegexp | REGEXP | Call onGet() only if Url matches pattern. | |
headers | ARRAY | List of name/value output header pairs. | initOnly |
interface | STRING | Interface for server to listen on, eg. 'eth0' or 'lo'. | initOnly |
local | BOOL | Limit connections to localhost addresses on the 127 network. | |
localhostName | STRKEY | Client name used by localhost connections ('localhost'). | |
maxConnects | INT | In server mode, max number of client connections accepted. | |
maxDownload | INT | Max size of file download. | |
maxUpload | INT | Max size of file upload will accept. | |
mimeTypes | OBJ | Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'}). | initOnly |
noConfig | BOOL | Disable use of conf() to change options after options after create. | initOnly |
noCompress | BOOL | Disable per-message-deflate extension which can truncate large msgs. | |
noUpdate | BOOL | Disable update event-processing (eg. to exit). | |
noWebsock | BOOL | Serve html, but disallow websocket upgrade. | initOnly |
noWarn | BOOL | Quietly ignore file related errors. | |
onAuth | FUNC | Function to call for http basic authentication. @function(ws:userobj, id:number, url:string, userpass:string) | |
onClose | FUNC | Function to call when the websocket connection closes. @function(ws:userobj|null, id:number) | |
onCloseLast | FUNC | Function to call when last websock connection closes. On object delete arg is null. @function(ws:userobj|null) | |
onFilter | FUNC | Function to call on a new connection: return false to kill connection. @function(ws:userobj, id:number, url:string, ishttp:boolean) | |
onGet | FUNC | Function to call to server handle http-get. @function(ws:userobj, id:number, url:string, query:array) | |
onOpen | FUNC | Function to call when the websocket connection occurs. @function(ws:userobj, id:number) | |
onUnknown | FUNC | Function to call to server out content when no file exists. @function(ws:userobj, id:number, url:string, query:array) | |
onUpload | FUNC | Function to call handle http-post. @function(ws:userobj, id:number, filename:string, data:string, startpos:number, complete:boolean) | |
onRecv | FUNC | Function to call when websock data recieved. @function(ws:userobj, id:number, data:string) | |
port | INT | Port for server to listen on (8080). | initOnly |
post | STRING | Post string to serve. | initOnly |
protocol | STRKEY | Name of protocol (ws/wss). | |
realm | STRKEY | Realm for basic auth (jsish). | |
recvBufMax | INT | Size limit of a websocket message. | initOnly |
recvBufTimeout | INT | Timeout for recv of a websock msg. | initOnly |
redirMax | BOOL | Temporarily disable redirects when see more than this in 10 minutes. | |
rootdir | STRING | Directory to serve html from ("."). | |
stats | options | Statistical data. | readOnly |
startTime | TIME_T | Time of websocket start. | readOnly |
includeFile | STRKEY | Default file when no extension given (include.shtml). | |
urlPrefix | STRKEY | Prefix in url to strip from path; for reverse proxy. | |
urlRedirect | STRKEY | Redirect when no url or / is given. Must match urlPrefix, if given. | |
use_ssl | BOOL | Use https (for client). | initOnly |
useridPass | STRKEY | The USERID:PASSWORD to use for basic authentication. | |
version | OBJ | WebSocket version info. | readOnly |
Option | Type | Description | Flags |
clientIP | STRKEY | Client IP Address. | readOnly |
clientName | STRKEY | Client hostname. | readOnly |
echo | BOOL | LogInfo outputs all websock Send/Recv messages. | |
headers | ARRAY | List of name/value output header pairs. | |
isWebsock | BOOL | Socket has been upgraded to a websocket connection. | |
onClose | FUNC | Function to call when the websocket connection closes. @function(ws:userobj|null, id:number) | |
onGet | FUNC | Function to call to server handle http-get. @function(ws:userobj, id:number, url:string, query:array) | |
onUnknown | FUNC | Function to call to server out content when no file exists. @function(ws:userobj, id:number, url:string, args:array) | |
onRecv | FUNC | Function to call when websock data recieved. @function(ws:userobj, id:number, data:string) | |
onUpload | FUNC | Function to call handle http-post. @function(ws:userobj, id:number, filename:string, data:string, startpos:number, complete:boolean) | |
rootdir | STRING | Directory to serve html from ("."). | |
stats | options | Statistics for connection. | readOnly |
query | ARRAY | Uri arg values for connection. | |
url | DSTRING | Url for connection. | |
Method | Prototype | Description |
append | append(archive:string, filelist:array, path:string|null=void, filelist:array=void, path:string|null=void, ...):void | Like 'create()', but appends to an existing archive (with no dup checking). |
create | create(archive:string, filelist:array, path:string|null=void, filelist:array=void, path:string|null=void, ...):void | Create a zip with the given files in prefix path. This command creates a zip archive and adds files to it. Files are relative the given 'path', or the current directory. If the destignation file already exist but is not an archive (eg. an executable), zip data is appended to the end of the file. If the existing file is already an archive, an error will be thrown. To truncate an existing archive, use zvfs.truncate(). Or use zvfs.append() instead.
zvfs.create('foo.zip',['main.js', 'bar.js'], 'src', ['a.html', 'css/a.css'], 'html'); |
deflate | deflate(data:string):string | Compress string using zlib deflate. |
inflate | inflate(data:string):string | Uncompress string using zlib inflate. |
list | list(archive:string):array | List files in archive. Return contents of zip directory as an array of arrays. The first element contains the labels, ie:
[ 'Name', 'Special', 'Offset', 'Bytes', 'BytesCompressed' ] |
mount | mount(archive:string, mountdir:string=void):string | Mount zip on mount point. Read a ZIP archive and make entries in the virutal file hash table for all files contained therein. |
names | names(mountdir:string=void):array | Return all zvfs mounted zips, or archive for specified mount. Given an mount point argument, returns the archive for it. Otherwise, returns an array of mount points |
offset | offset(archive:string):number | Return the start offset of zip data. Opens and scans the file to determine start of zip data and truncate this off the end of the file. For ordinary zip archives, the resulting truncated file will be of zero length. If an optional bool argument can disable errors. In any case, the start offset of zip data (or 0) is returned. |
stat | stat(filename:string):object | Return details on file in zvfs mount. Return details about the given file in the ZVFS. The information consists of (1) the name of the ZIP archive that contains the file, (2) the size of the file after decompressions, (3) the compressed size of the file, and (4) the offset of the compressed data in the archive. |
truncate | truncate(archive:string, noerror:boolean=false):number | Truncate zip data from archive. Opens and scans the file to determine start of zip data and truncate this off the end of the file. For ordinary zip archives, the resulting truncated file will be of zero length. If an optional bool argument can disable errors. In any case, the start offset of zip data (or 0) is returned. |
unmount | unmount(archive:string):void | Unmount zip. |