Created
February 28, 2015 15:21
-
-
Save undeadcat/5548c729896f87da752c to your computer and use it in GitHub Desktop.
FSharp.Data.SqlClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open FSharp.Data | |
open Microsoft.FSharp.Data.TypeProviders | |
open Microsoft.FSharp.Linq | |
open System | |
open System.Data | |
module UserQueries = | |
[<Literal>] | |
//design time only | |
let connStr = @"Data Source=localhost\Sqlexpress;Initial Catalog=mskr;Integrated Security=True" | |
type private fakeUserQuery = SqlCommandProvider< "SELECT top 1 * from Users", connStr > | |
type userType = fakeUserQuery.Record | |
type allUsers = SqlCommandProvider< "SELECT Login from Users", connStr > | |
type userByLogin = SqlCommandProvider< "select * from Users where Login=@login", connStr > | |
//doesn't compile | |
//type selectByWrongColumn = SqlCommandProvider<"select * from Abonent where Huj=@login", connStr> | |
//type selectByWrongTable = SqlCommandProvider<"SELECT * from Huj", connStr> | |
type maxManagerCount = SqlCommandProvider< @"select top 1 Login, count(distinct(Id)) t | |
from Users | |
where Type=1 | |
group by Login | |
order by t desc", connStr, SingleRow=true > | |
type UsersRepository(connStr : string) = | |
member __.selectAllLogins() = UserQueries.allUsers.Create(connStr).Execute() | |
member __.selectUserByLogin login = UserQueries.userByLogin.Create(connStr).Execute(login) | |
//let selectWithWrongParamType = (new userByLogin()).Execute(123) | |
member __.userWithMaxManagerCount() = UserQueries.maxManagerCount.Create(connStr).Execute() | |
module SomeModule = | |
let useTableType (x : UserQueries.userType seq) = x |> Seq.iter (Console.WriteLine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment