Skip to content
ForgeCastDocs

Data tools

Tables in storage, CSV, hashes and signatures, QR codes, redacting private details, time and schedules.

Functions

StoredTable:insert(row)

Add a row: its new id.

  • row: table

Returns integer id

StoredTable:get(id)

One row by its id, or nil.

  • id: integer

Returns table?

StoredTable:update(id, fields)

Change some fields of a row.

  • id: integer
  • fields: table

Returns boolean found

StoredTable:upsert(query, fields)

Update the first row that matches, or add one: its id.

  • query: Query
  • fields: table

Returns integer id

StoredTable:remove(id)

Delete a row.

  • id: integer

Returns boolean found

StoredTable:find(query, opts)

The rows that match, in order.

Returns table[]

StoredTable:first(query, opts)

The first row that matches, or nil.

Returns table?

StoredTable:count(query)

How many rows match (all of them without a query).

  • query: Query, optional

Returns integer

StoredTable:all(opts)

Every row.

Returns table[]

StoredTable:clear()

Delete every row.

storage.table(name)

A table of rows kept in the plugin's storage, found by their fields.

  • name: string

Returns StoredTable

storage.export_csv(rows, filename, callback)

Save rows (or a storage.table by its name) as a CSV file in the Downloads folder. callback(true) once it is saved, or (nil, why).

Name

Type

storage.save_file(name, text, callback)

Save a .csv, .txt or .json file (up to 2 MB) in the Downloads folder.

Name

Type

csv.encode(rows, columns)

Rows of tables (or of lists) as CSV text; the columns are the keys, sorted, unless you list them.

  • rows: table[]
  • columns: string[], optional

Returns string

csv.decode(text, opts)

CSV text as a list of tables keyed by the first row (or, with header = false, of lists).

  • text: string
  • opts: { header: boolean }, optional

Returns table[]

crypto.sha256(s)

SHA-256 of a string, as hex.

  • s: string

Returns string

crypto.hmac_sha256(key, message)

HMAC-SHA256 (to sign a webhook), as hex.

  • key: string
  • message: string

Returns string

crypto.base64_encode(s)

A string as standard base64.

  • s: string

Returns string

crypto.base64_decode(s)

Standard or URL-safe base64 back to a string, or nil when it isn't base64.

  • s: string

Returns string?

crypto.uuid()

A random id like "3f2b…-4…".

Returns string

qr.make(text, opts)

A QR code as a picture for ui.image (an svg data address).

  • text: string. up to 1000 characters
  • opts: { size: integer, color: string, background: string }, optional

Returns string

privacy.redact(text, opts)

Text with emails, phone numbers, UPI ids, card numbers and links replaced by [email], [phone], [upi], [card] and [link]: for anything you send on (http, ai). Turn one off with { links = false }.

  • text: string
  • opts: { emails: boolean, phones: boolean, upi: boolean, cards: boolean, links: boolean }, optional

Returns string

time.format(ms, fmt)

A moment as text on this PC's clock: YYYY MM MMM DD ddd HH hh mm ss A ("HH:mm" by default), or a strftime pattern with % ("%H:%M").

  • ms: integer, optional. milliseconds since 1970 (now by default)
  • fmt: string, optional

Returns string

time.duration(ms)

"1h 05m", "4m 09s", "12s".

  • ms: integer

Returns string

schedule.daily(hhmm, fn)

Run every day at a time on this PC's clock ("21:00"). Returns an id for schedule.cancel.

  • hhmm: string
  • fn: fun()

Returns integer id

schedule.at(ms, fn)

Run once at a moment (milliseconds since 1970, like time.now() + 60000).

  • ms: integer
  • fn: fun()

Returns integer id

schedule.next(id)

When a job runs next, or nil.

  • id: integer

Returns integer?

schedule.cancel(id)

Stop a job made with schedule.daily or schedule.at.

  • id: integer

Returns boolean found

Types

Open a type to see its fields; type names above link here.

On this page