RingDotNetfor Ring

Entity Framework reference

Every method of RingDatabase and RingEntityDb, the schema format, the query specification, hooks and limits.

Schema format#

Ring
aSchema = [
	[ "TableName",
	  [ [ "Column", "type", isKey, [ ["option", value], ... ] ],  ... ],
	  [ ["tableOption", value], ... ]                                   # optional
	],
	...
]
PartValues
column typeint, long, double, decimal, string (or text), bool, datetime, bytes
isKey1 for a key column; several give a composite key. A single int/long key is generated by the database
column optionsrequired, nullable, unique, index, maxlength, default, references, ondelete, convert
table options["filter", condition] — a global query filter

Creating a database#

Ring
oDb = new RingDatabase(connection, aSchema)       # rows as [name, value] pairs
oDb = new RingEntityDb(connection, aSchema)       # real entity objects

The connection starts with the provider name (inmemory:, sqlserver:, postgres:, mysql:) or is a SQLite connection string.

RingDatabase#

Rows#

MethodReturns
insert(table, values)the key (a list for a composite key). values is [["Name","Ann"],["Age",31]]
byKey(table, key)the row, or "". The row is tracked: after raw SQL, call discard() to read the new values
all(table)all rows
where(table, condition, params)rows matching a SQL condition with {0} parameters (SQLite)
update(table, key, values)1 when the row exists, else 0
remove(table, key)1 when the row existed, else 0
count(table)the number of rows
dbValue(row, column)a column of a row ("" for null)

Queries#

MethodDoes
query(table, spec)rows matching a query specification
countWhere(table, cond)number of rows that match ([] for all)
sum, min, max, average(table, column, cond)aggregates
groupCount(table, column, cond)[[value, count], ...]
sqlRows(sql, params)rows of any SELECT as [column, value] lists
execute(sql, params)runs a statement, returns the rows affected
scalar(sql)the first value of the first row

Relationships#

MethodReturns
children(parentTable, key, childTable)the rows of the child table that belong to the parent
parent(childTable, key, parentTable)the parent row, or ""
include(table, relatedTable)[[row, children-or-parent], ...] in two queries

Transactions and saving#

MethodDoes
begin(), commit(), rollback()a transaction; an error in commit() undoes everything
inTransaction()true while a transaction is active
autoSave(flag), save()batch changes; pendingChanges() lists them
discard()forget changes that were not saved
insertAsync, allAsync, whereAsync, countAsync, saveAsyncreturn a Task; dbWait(task) returns the result

Schema and migrations#

MethodDoes
migrate()creates missing tables, columns and indexes; returns the list of changes (SQLite)
apply(name, sql)runs a SQL change once; 1 when applied now, 0 when applied before
applied()names of the applied changes
columnInfo(table, column)[["name",..],["type",..],["key",..],["nullable",..],["required",..],["unique",..],["index",..],["maxlength",..]]

Hooks#

MethodDoes
onSaving(dnCallback("f"))f(aArgs) runs before changes are written; aArgs[1] is [[table, state, row], ...] (state: Added, Modified, Deleted). Return a text to cancel the save.
onSaved(dnCallback("f"))aArgs[1] is the number of rows written
onLog(dnCallback("f"))aArgs[1] is the text of each SQL command
pendingChanges()changes waiting to be saved: [[table, state, row], ...]

Other#

MethodDoes
context()the real EF DbContext (a wrapped object)
close()dispose and release the database file

RingEntityDb#

MethodDoes
newEntity(table)a new object of the generated class
entityType(table)the .NET Type
properties(table)the property names: columns first, then navigations (Author, Books)
add(entity)adds the entity (and the entities it refers to); returns the key
remove(entity)removes it
find(table, key)the tracked entity, or ""
query(table, spec)tracked entities; the specification also accepts ["include",["Author","Other.Nested"]]
all(table), count(table, cond)all entities, number of entities
getValue(entity, property), setValue(entity, property, value)read or write a property (dates are texts, bytes are hex)
toRow(entity), fill(entity, values)columns as [name, value] pairs
save(), autoSave(flag), discard()saving
begin(), commit(), rollback()transactions
context(), close()the DbContext, release

Entities are plain DotNetObjects: oBook.getProp("Title"), oBook.setProp("Author", oAuthor); a collection navigation has getProp("Count") and toList().

Query specification#

A query is a list of [item, value] pairs:

ItemValue
wherea condition
orderby[[column, "asc"/"desc"], ...]
skip, takenumbers
select[column, ...] — keeps only those columns (RingDatabase)
include[navigation, ...] (RingEntityDb)
ignorefilters1 to ignore the table's global filter

A condition is [column, op, value] or a combination:

FormMeaning
["Age", ">", 30]comparison: = != < <= > >=
["Name", "contains", "an"]contains, startswith, endswith (text)
["City", "in", ["Cairo","Giza"]]membership
["Boss", "isnull"], ["Boss", "notnull"]null checks
["and", c1, c2, ...], ["or", c1, c2, ...], ["not", c]combinations

Providers and capabilities#

CapabilitySQLiteIn-memorySQL Server / PostgreSQL / MySQL
tables, rows, relations, queries (expression trees), aggregates✔✔untested
where / execute / scalar / sqlRows with SQL✔—untested
migrate / apply✔——
transactions✔✔untested
typed entities (RingEntityDb)✔✔untested

What is not supported#

Where to go next#

RingDotNet — use .NET classes and methods from Ring programs. Screenshots and output on these pages come from the real samples.