Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A set of F# Type Providers for statically typed access to MS SQL database

License

NotificationsYou must be signed in to change notification settings

fsprojects/FSharp.Data.SqlClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library exposes SQL Server Database objects in a type safe manner to F# code, by the mean ofType Providers

You can reference it in F# Interactive that ships with Visual Studio

#r"nuget: FSharp.Data.SqlClient"openFSharp.DataopenFSharp.Data.SqlClientlet [<Literal>]connectionString="Server=.;Database=AdventureWorks2012;Trusted_Connection=True;"typeMyCommand= SqlCommandProvider<"""selectdata.afrom(select 1 a union all select 2 union all select 3) datawheredata.a > @data""", connectionString>;;(new MyCommand(connectionString)).Execute(data=1)|> Seq.toArray|> printfn"%A"

dotnet fsi is not supported yet.

Quick Links

Type Providers

SqlCommandProvider

Provides statically typed access to the parameters and result set of T-SQL command in idiomatic F# way(*).

openFSharp.Data[<Literal>]letconnectionString="Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True;TrustServerCertificate=true"// The query below retrieves top 3 sales representatives from North American region with YTD sales of more than one million.douse cmd=new SqlCommandProvider<"        SELECT TOP(@topN) FirstName, LastName, SalesYTD        FROM Sales.vSalesPerson        WHERE CountryRegionName = @regionName AND SalesYTD > @salesMoreThan        ORDER BY SalesYTD", connectionString>(connectionString)    cmd.Execute(topN=3L, regionName="United States", salesMoreThan=1000000M)|> printfn"%A"

output

seq[("Pamela","Ansman-Wolfe",1352577.1325M);("David","Campbell",1573012.9383M);("Tete","Mensa-Annan",1576562.1966M)]

SqlProgrammabilityProvider

Exposes Tables, Stored Procedures, User-Defined Types and User-Defined Functions in F# code.

typeAdventureWorks= SqlProgrammabilityProvider<connectionString>douse cmd=new AdventureWorks.dbo.uspGetWhereUsedProductID(connectionString)for xin cmd.Execute( StartProductID=1, CheckDate= System.DateTime(2013,1,1))do//check for nullsmatch x.ProductAssemblyID, x.StandardCost, x.TotalQuantitywith| Some prodAsmId, Some cost, Some qty->             printfn"ProductAssemblyID:%i, StandardCost:%M, TotalQuantity:%M" prodAsmId cost qty|_->()

output

ProductAssemblyID:749, StandardCost:2171.2942, TotalQuantity:1.00ProductAssemblyID:750, StandardCost:2171.2942, TotalQuantity:1.00ProductAssemblyID:751, StandardCost:2171.2942, TotalQuantity:1.00

SqlEnumProvider

Let's say we need to retrieve number of orders shipped by a certain shipping method since specific date.

//by convention: first column is Name, second is ValuetypeShipMethod= SqlEnumProvider<"    SELECT Name, ShipMethodID FROM Purchasing.ShipMethod ORDER BY ShipMethodID", connectionString>//Combine with SqlCommandProviderdouse cmd=new SqlCommandProvider<"        SELECT COUNT(*)        FROM Purchasing.PurchaseOrderHeader        WHERE ShipDate > @shippedLaterThan AND ShipMethodID = @shipMethodId", connectionString, SingleRow=true>(connectionString)//overnight orders shipped since Jan 1, 2008    cmd.Execute( System.DateTime(2008,1,1), ShipMethod.``OVERNIGHT J-FAST``)|> printfn"%A"

output

Some(Some1085)

SqlFileProvider

typeSampleCommand= SqlFile<"sampleCommand.sql">typeSampleCommandRelative= SqlFile<"sampleCommand.sql","MySqlFolder">use cmd1=new SqlCommandProvider<SampleCommand.Text, ConnectionStrings.AdventureWorksNamed>()use cmd2=new SqlCommandProvider<SampleCommandRelative.Text, ConnectionStrings.AdventureWorksNamed>()

More information can be found in thedocumentation.

Build Status

WindowsLinuxNuGet
Build status (Windows Server 2012, AppVeyor)Build StatusNuGet Status

Maintainers

The default maintainer account for projects under "fsprojects" is@fsprojectsgit - F# Community Project Incubation Space (repo management)

Thanks Jetbrains for their open source license program and providing their tool.

About

A set of F# Type Providers for statically typed access to MS SQL database

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors30


[8]ページ先頭

©2009-2025 Movatter.jp