gpt4 book ai didi

mysql - F# 连接到在线 MySQL DB 执行查询

转载 作者:可可西里 更新时间:2023-11-01 08:04:18 25 4
gpt4 key购买 nike

我正在制作一个 F# 项目,需要对在线 mysql 数据库进行一些数据库查询。谁能帮帮我吗。我需要这样的东西

    \\  Connect to DB
let servername = "localhost"
let username = "username"
let password = "password"
\\ Code that connects to db
\\ Print error message if can connect

\\ Query
let query = "SELECT * FROM table ..."
\\ Code that executes query
\\ Error Message if query not executed

最佳答案

您应该为 MySQL 安装 .NET 驱动程序。然后安装 SQLprovider。文档中有 MySQL 的示例。您将连接到数据库并像这样查询它:

type sql = SqlDataProvider<
dbVendor,
connString,
ResolutionPath = resPath,
IndividualsAmount = indivAmount,
UseOptionTypes = useOptTypes,
Owner = "HR"
>
let ctx = sql.GetDataContext()

let employees =
ctx.Hr.Employees
|> Seq.map (fun e -> e.ColumnValues |> Seq.toList)
|> Seq.toList

connstring 将是这样的:

[<Literal>]
let connString = "Server=localhost;Database=HR;User=root;Password=password"

您还应该阅读 https://msdn.microsoft.com/visualfsharpdocs/conceptual/walkthrough-accessing-a-sql-database-by-using-type-providers-%5bfsharp%5d

关于mysql - F# 连接到在线 MySQL DB 执行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37415001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com