出于演示目的,我正在制作一个插入函数,我想返回传入类型的变量。
我是初始查询的用户 Dapper.fsharp,然后我想运行原始 SQL 查询来获取最后插入的值。
所以我有这样的东西用于演示目的
let Insert<'a> asyncQuery =
asyncQuery
|> connection.InsertAsync<'a>
|> RunSynchronously
|> ignore
(*This is a Dapper.fsharp query. Running this returns the number of rows inserted (int) *)
let table = asyncQuery.Table (*This is a string*)
let result =
connection.Query<'a>($"""Select * From {table} Where id = (select last_insert_id())""") (*Should return an IENumerable of type 'a*)
|> EnumerableToArray
result |> first
Run Code Online (Sandbox Code Playgroud)
然后这就是所谓的
let newSession =
insert {
table "sessions"
value newSession
} |> Insert
Run Code Online (Sandbox Code Playgroud)
其中 newSession 是会话类型
module Session
type session = {id: int; session_id: string; clerk_json: string; clerk_id: int; expires: int}
(*This is also the structure of the SQL table exactly*)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
"A parameterless default constructor or one matching signature (System.Int32 id, System.String session_id, System.Int32 clerk_id, System.String clerk_json, System.Int32 expires) is required for Session+session materialization"
Run Code Online (Sandbox Code Playgroud)
这向我表明它没有从数据库获取正确的类型签名,但列名和类型匹配,并且表中没有任何内容为空。
也许我忽略了一些简单的事情或误解了应该如何使用该库?