The key things missing in the original functor argument are a folder for
[u] and a record of [sql_injectable] instances for it, both of which
you'll see used in similar UPO functions mentioned earlier.
BTW, the type of [insert] (in lib/ur/basis.urs) isn't magic and can be
inspected just like any Ur type, and it should be possible to understand
from first principles.
On 02/11/2017 04:19 AM, [email protected] wrote:
Actually, it might be quite simple.
Incomplete, but, hopefully, clear example:
table tab : $([Ix = int] ++ someColumns ++ otherColumns) PRIMARY KEY Ix
fun test () : transaction xbody =
<...>
tn <- now;
easy_insert tab ({Ix = ix} ++ field_defaults ++ {Dated = tn});
<...>
11. Feb 2017 22:09 by [email protected] <mailto:[email protected]>:
Sergey,
Something similar to this:
https://github.com/achlipala/upo/blob/master/sql.ur#L44
and this:
https://github.com/achlipala/upo/blob/master/sql.ur#L50
might help you a bit.
Also check other functions in sql.ur
I believe you also can figure out desugared type expressions from
compiler error output if you replace parts of your code with
simple expressions of known type.
https://wiki.haskell.org/GHC/Typed_holes
11. Feb 2017 21:18 by [email protected] <mailto:[email protected]>:
Hi. I'm trying (again) to write an Ur/Web module to provide
API for
managing OS-level processes. I expect users to pass it a table
containing _at_least_ id, process command name, arguments,
placeholder
for exit code and status string. It is expected that users
will use
tables containing more problem-specific columns.
The problem is that I cant use simple dml operations anymore. As a
start, I tried to write dummy insert using [demo/more/orm.ur] as
example, but was stopped by difficult [ensql] function. Could you
please help me to implement it? The code is quite short and listed
below.
Regards,
Sergey
---
con jobinfo = [
Id = int
, ExitCode = option int
, Cmd = string
, Hint = string
]
functor Make(M : sig
con u
constraint [Id,ExitCode,Cmd,Hint] ~ u
table t : (jobinfo ++ u)
sequence s
end) = struct
open CallbackFFI
type row' = record (jobinfo ++ M.u)
(* fun ensql [avail ::_] (r : row') : $(map (sql_exp avail []
[]) fs') = *)
(* @map2 [meta] [fst] [fn ts :: (Type * Type) => sql_exp avail
[] [] ts.1] *)
(* (fn [ts] meta v => @sql_inject meta.Inj v) *)
(* M.folder M.cols r *)
(* createSync will start the job, but in this example it just
does a
simple insert.
args is a problem-specific part of the table record.
How to make this dml(insert..) work? *)
fun createSync (ji : record jobinfo, args : record M.u) :
transaction (option int) =
i <- nextval M.s;
dml(insert M.t ({Id = sql_inject ji.Id,
ExitCode = sql_inject ji.ExitCode,
Cmd = sql_inject ji.Cmd,
Hint = sql_inject ji.Hint} ++ (ensql args) ));
return (Some i)
end
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur