Giter Site home page Giter Site logo

Comments (14)

dmitry-a-morozov avatar dmitry-a-morozov commented on August 23, 2024

Robert,
I think there are 2 ways to approach this problem without changing TP.

  1. If you have enough control over a database pull big chunks of SQL into reusable FUNCTIONs and VIEWs. You can combine them with APPLY operator. It's great practice.
  2. Have dedicated F# file that contains sql scripts and type aliases for commands. It's similar to what I have on WebApi example
    http://github.com/dmitry-a-morozov/FSharp.Data.SqlCommandTypeProvider/blob/master/WebApi/DataAccess.fs
    It will be kinda "Repository" pattern.

from fsharp.data.sqlclient.

rojepp avatar rojepp commented on August 23, 2024
  1. There are cases for and against this, and like you touched upon, you don't always have control over the db. When many apps are hitting a single db, I think it is downright inappropriate. :)
  2. This is what I would do if I had to. Actually, with external files, in a bigger app, I still would do this, just to keep the type definitions in a single place.

FSharp.Data implements this and it is pretty good. You can have your file as a proper .sql file with all the benefits of that;

  • Syntax coloring
  • Intellisense
  • Error squigglies
  • diffs are nicer

Last time I looked in FSharp.Data, it was actually the same parameter. If it looks like a file name and the file exists, read the file, otherwise parse the content. Good enough, but maybe have an optional 'content' param and an optional 'filename' param? If both exist or none exist=compile error.

from fsharp.data.sqlclient.

dsevastianov avatar dsevastianov commented on August 23, 2024

Good point. We agreed to do it FSharp.Data - style.

from fsharp.data.sqlclient.

ovatsus avatar ovatsus commented on August 23, 2024

If you want to reuse that piece from FSharp.Data, use the parseTextAtDesignTime function (https://github.com/ovatsus/FSharp.Data/blob/Async/src/Providers/Helpers.fs#L105)

from fsharp.data.sqlclient.

dmitry-a-morozov avatar dmitry-a-morozov commented on August 23, 2024

@ovatsus Thanks for suggestion.

from fsharp.data.sqlclient.

dsevastianov avatar dsevastianov commented on August 23, 2024

@ovatsus The link is broken :( I guess you meant https://github.com/ovatsus/FSharp.Data/blob/master/src/Providers/Helpers.fs#L105

from fsharp.data.sqlclient.

ovatsus avatar ovatsus commented on August 23, 2024

Yes, or https://github.com/fsharp/FSharp.Data/blob/master/src/Providers/Helpers.fs#L105

from fsharp.data.sqlclient.

dmitry-a-morozov avatar dmitry-a-morozov commented on August 23, 2024

@rojepp, We didn't forget your request - @dsevastianov will work on this feature.

from fsharp.data.sqlclient.

rojepp avatar rojepp commented on August 23, 2024

@dsevastianov Great! I will test it later.

from fsharp.data.sqlclient.

dsevastianov avatar dsevastianov commented on August 23, 2024

@rojepp My pleasure. This is naive implementation, I decided not to go with full-fledged implementation as in FSharp.Data just yet. We might want to look into some caching later on as well, it's getting a bit slow.

from fsharp.data.sqlclient.

rojepp avatar rojepp commented on August 23, 2024

By full-fledged, you mean change notification?

I haven't noticed it being slow yet..

from fsharp.data.sqlclient.

dsevastianov avatar dsevastianov commented on August 23, 2024

I mean, with support for web URIs, caching, async reads, etc.

from fsharp.data.sqlclient.

rojepp avatar rojepp commented on August 23, 2024

Just tried it out, works fine!

I think it is pretty unlikely that someone would put their Sql code on a web page and use that for building their software. :) Also, async is pretty pointless if you immediately have to wait for it to finish, which should be the case here. What I'm missing is change notification. When I edit the sql file and save it, types should immediately update, like in FSharp.Data.
Maybe I should put it in an issue of its own?

from fsharp.data.sqlclient.

dsevastianov avatar dsevastianov commented on August 23, 2024

Yes, if you could. I'd expect it's going to be tricky.

from fsharp.data.sqlclient.

Related Issues (20)

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.