GithubHelp home page GithubHelp logo

alextroshkin / fsharp-dapper Goto Github PK

View Code? Open in Web Editor NEW
69.0 4.0 7.0 147 KB

The wrapper above the 'Dapper' library allows you to write more familiar code in the F # language. It also contains a functional for more simple work with temporary tables

License: MIT License

F# 97.09% PowerShell 2.91%
fsharp dapper orm temporary-tables

fsharp-dapper's People

Contributors

alextroshkin avatar samritchie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fsharp-dapper's Issues

License?

There's a part of this project I'd like to use, but there's no license indicated anywhere in the repository that I have found thus far. Could you add a license for clarity?

Example of inserting data?

I'm currently using a code snippet very similar to the below in order to insert data into a table, based on a tutorial page about inserting 'bird' objects into a database.

What is the proper way to do this? It looks like in 1.0, there was an ExecuteAsync but I'm not seeing how to call that function now.

        let internal writeItemToDb conn itemId itemName = 
            let result = 
                querySingleAsync<int> (conn)
                    {
                        script "
                            UPDATE items SET name=$n WHERE id = $id;
                        
                            INSERT OR IGNORE INTO items
                            (name,id)
                            VALUES ($n,$id);
                            
                            // required to not get empty sequence error
                            select count(1) from items where id = $id"
                        parameters (dict [
                            ;"n",box itemName
                            ;"id",box itemId])
                    }
            let syncres = Async.RunSynchronously result
            match syncres with
            |1 -> Ok() // 1 row affected
            |_ -> Error (sprintf "Cannot upsert item id %s to database" itemId)

Connection management in 2.0?

Connection state management doesn’t seem to be working for me in 2.0 and I’m unsure exactly what’s wrong. If I open the connection first I get a The connection was not closed. The connection's current state is open. in [email protected](IDbConnection connection). If I leave the connection closed I get Invalid operation. The connection is closed. in Dapper.SqlMapper.<QueryRowAsync>d__34``1.MoveNext(). Looks like Table.Scope explicitly opens the connection first but I can’t tell why.

I’m using dotnet 2.1.302, SqlClient 4.5.1, Dapper 1.50.5. Thanks in advance for any help understanding what’s going on...

Can this library be used with MySql?

I see that Connection has only 2 cases: SqlLite and SqlServer.
I note that the docs say that temporary tables only work for these 2 cases.
Does that mean the entire library is not usable for anything but these 2 cases?

How to use this library in a testable way?

Hello,

I want to extract the connection part from the code to make it testable. I have introduced a class like the following:

module Queries =
    type Schema (connectionF: unit -> Connection) =

        member __.CreateTables () = querySingleAsync<int> connectionF {
            script """
                DROP TABLE IF EXISTS Bird;
                CREATE TABLE Bird (
                    Id INTEGER NOT NULL PRIMARY KEY,
                    Name VARCHAR(255) NOT NULL,
                    Alias VARCHAR(255) NULL
                );
            """
    }

Unfortunately, when I try to create the schema, I get the following exception:

System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.ThrowZeroRows(Row row) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1160
at Dapper.SqlMapper.QueryRowAsync[T](IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command)
in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 485

If I add the following to Queries module, it works as expected:

let private mkOnDiskConnectionString (dataSource: string) = sprintf "Data Source = %s;" dataSource
let mkOnDisk () = new SqliteConnection (mkOnDiskConnectionString "./example.db")
let private connectionF2 () = Connection.SqliteConnection (mkOnDisk())
let querySeqAsync2<'R> = querySeqAsync<'R> (connectionF2)
let querySingleAsync2<'R> = querySingleOptionAsync<'R> (connectionF2)
member __.CreateTables () = querySingleAsync2<int> {
    script """ ... """
}

What should I do to extract the connection part ? I cannot move QueryBuilders to Schema type because of generic parameters...

Thanks for your help!

"It also contains a functional for"

Perhaps what is meant is "functional approach" ?

I.e. that the project description should be:
"The wrapper above the 'Dapper' library allows you to write more familiar code in the F # language. It also contains a functional approach for more simple work with temporary tables"
?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.