ORT-RUST(1) | General Commands Manual | ORT-RUST(1) |
ort-rust
—
generate rust module
ort-rust |
[config...] |
Accepts ort(5) config files, defaulting to standard input, and generates a Rust module.
The output requires the "base64", "bcrypt", "json", "libsqlite3-sys", "num-derive", "num-traits", and "rusqlite" dependencies.
This mode is currently experimental.
The output is wrapped in a module "ort". In this manual, the leading "ort::" to submodules, structures, and so on is omitted for brevity. For example, the ort::Ortdb type is written as simply Ortdb.
An application context is initialised with the following Ortdb associated functions:
new
(dbname:
&str) ->
Ortdbnew_with_args
(dbname:
&str, args: Ortargs)
-> Ortdbnew
(), but accepting
args consisting of configuration parameters. If
provided, it must define the bcrypt_cost property
with a valid number of password hashing rounds.The Ortdb type has the following method:
connect
()
->
Result<Ortctx>Each sequence of database interaction begins with
the
connect
()
method from the application-wide Ortdb instance.
Any insert
statements are output as
follows. Let "foo" be the name of the exemplar structure in this
and subsequent prototypes. Its full module path is
ort::objs::Foo, written here as simply
Foo. Returns an error Result on
database error.
db_foo_insert
(ARGS)
-> Result<i64>rowid
, which is automatically set by the
database. If any fields are specified as null
,
they may be passed as None
options.Query statements count
,
iterate
, list
,
search
are output as follows. These return an error
Result on database error.
db_foo_count
()
-> Result<i64>db_foo_count_xxxx
()
but returning a count of all rows.db_foo_count_xxxx
(ARGS)
-> Result<i64>db_foo_get_xxxx
(),
but returning a count of responses.db_foo_count_by_xxxx_op1_yy_zz_op2
(ARGS)
-> Result<i64>db_foo_get_by_xxxx_op1_yy_zz_op2
(),
but returning a count of responses.db_foo_get_xxxx
(ARGS)
->
Result<Option<Foo>>search
statement named "xxxx". The
function accepts variables for all binary-operator fields to check (i.e.,
all except for those checking for null).db_foo_get_by_xxxx_op1_yy_zz_op2
(ARGS)
->
Result<Option<Foo>>db_foo_get_xxxx
(), but for (possibly-nested)
structures. In the given example, "xxxx" is a field in the given
structure with operation "op1" and "yy_zz" means a
field "zz" in the nested structure "yy" with operation
"op2".db_foo_iterate
(ARGS,
cb) ->
Result<()>db_foo_iterate_xxxx
()
but iterating over all rows.db_foo_iterate_xxxx
(ARGS,
cb) ->
Result<()>db_foo_get_xxxx
(), but invoking a function
callback per row. The cb callback accepts a single
parameter of type Foo and does not have a return
value.db_foo_iterate_by_xxxx_op1_yy_zz_op2
(ARGS,
cb) ->
Result<()>db_foo_get_by_xxxx_op1_yy_zz_op2
(), but
invoking a function callback for each retrieved result.db_foo_list
()
->
Result<Vec<Foo>>db_foo_list_xxxx
()
but allocating and filling a queue of all rows.db_foo_list_xxxx
(ARGS)
->
Result<Vec<Foo>>db_foo_get_xxxx
(), but producing an array of
responses.db_foo_list_by_xxxx_op1_yy_zz_op2
(ARGS)
->
Result<Vec<Foo>>db_foo_get_by_xxxx_op1_yy_zz_op2
(), but
producing a queue of responses.Any update
statements in the configuration
are output as the following methods on Ortctx. These
return an error Result on database error.
db_foo_update_xxxx
(ARGS)
-> Result<bool>update
statements. The parameters
passed to this function are first the fields to modify, then the fields
that constrain which rows are updated. Update fields are only specified
for operations for binary-operator constraints, i.e., those not checking
for null status. Returns true on success, false on constraint
failure.db_foo_update_xx_mod_by_yy_op
(ARGS)
-> Result<bool>db_foo_update_xxxx
(), but using an un-named
update statement modifying "xx" with modifier "mod"
constrained by "yy" with operation "op". Either or
both modifiers and constraints may be empty. If modifiers are empty, all
fields are modified by setting. If constraints are empty, they and the
preceding "by" are omitted.Any delete
statements in the configuration
are output as the following methods on Ortctx. These
return an error Result on database error.
db_foo_delete_xxxx
(ARGS)
-> Result<()>delete
function "xxxx".
The ARGS passed to this function are the fields that
constrain which rows are deleted. Parameters are only specified for
operations for binary-operator constraints, i.e., those not checking for
null status.db_foo_delete_by_yy_op
(ARGS)
-> Result<()>db_foo_delete_xxxx
(), but using an un-named
delete
statement constrained by "yy"
with operation "op".All database functions will return a rusqlite::Error in its Result on error. This may be examined for how to respond in the manner documented in its crate.
Any enumerations or bitfields (enum
,
bitf
) in the configuration are output in the
ort::data submodule and named as themselves.
Enumerations have explicit discriminator values set to the item value.
Bitfields also have explicit discriminator, but assigned the bit index (from
one).
Each struct
is output as a structure in
the ort::data module and named as itself, such as
ort::data::Foo. All items of the structure are mapped
to fields with the following types:
bit |
i64 |
bits |
i64 |
blob |
Vec<u8> |
date |
i64 |
email |
String |
enum |
ort::data::Enumname |
epoch |
bigint |
int |
i64 |
password |
String |
real |
f64 |
text |
String |
Since bitfields are combinations of bits in their respective enumerations, they are represented by i64 and not the enumeration type.
If a field is marked as null
, it will be
wrapped in an Option, such as
Option<String>.
Objects returned by query methods are output as structures in the ort::objs module and named as in the configuration. Letting "foo" be an exemplar structure name, ort::objs::Foo, the object consists of the following.
export
()
-> StringThe exported object is readable by applications using the ort-javascript(1) tool.
The ort-rust
utility exits 0 on
success, and >0 if an error occurs.
October 25, 2021 | OpenBSD 6.7 |