Now that SQL Server is working better with JSON it is becoming easier to just put plain JSON into columns. It’s nice to be able to query the JSON directly in the database. The other day I was wanted to get a list of values in arrays. Here’s how I did it. First let’s set up the table: DECLARE @JSON TABLE ( JsonID INT PRIMARY KEY IDENTITY(1, 1) , JsonData nvarchar(max) NOT NULL ); Some test data:
Originally when I was planning on doing a post for the F# Advent Calendar I was thinking I would do one on a tool I’m building for C# in F# that mimicks some of the functionality of the fantastic library FSharp.Data.SqlClient. But then I was thinking, “I’ve been messing around with F# for a while and have done some production work with it; why not share some of the experiences that I have had with F#?
Desert Code Camp 2017 was yesterday. I was slated to give four presentations yesterday. I ended up giving three. Three of them were on F#. I did Introduction to F# in the morning and had two more ready to go in the evening. But by that time everyone in the morning had already gone home, I’m guessing, and so the evening attendees probably would have enjoyed hearing Introduction to F# again!
There are two different ways people like to write their SQL scripts when calling the database. One way is to write the SQL statements in their application code. Sometimes they will write an ORM to make this process similar to their language constructs. Sometimes they will write the SQL code directly in procedures. Pros and Cons of Developing in the Application Pros Low friction between application and database. Any refactoring in your application is simple since all your code is accessed in the same location.
From what I understand static typing makes programmers more productive and gives implicit documentation to the code base although explicit documentation is also very helpful. It also seems to make the tools we use much more powerful. One of the problems of static typing is that your code becomes more verbose. With programming languages like F# the compiler will implicitly type as much of your program as possible. Where it fails, you need to type it yourself.
One thing that really got me frustrated in WebAPI 2.0 was creating custom authentication. Eventually I found a blog post by Rick Strahl that showed how to roll your own authentication/authorization. I wanted to implement a login (Basic Authentication) with username/password that would return a token for later (Bearer Authorization) use. It was quite simple but really frustrating because there wasn’t a whole lot of documentation on the subject. Now I want to do something similar for ASP.
I presented at the 2016 Desert Code Camp. The topic was WebAPI with F#. I also did a video series to go along with the talk. The talk and video series basically goes over how to use F# in a functional manner by building out all the pieces from scratch. Here’s the series, hope you enjoy it! F# WebAPI From Start to Finish. Some set up steps and notes that are important to the success of the project:
The full code for this article is up on GitHub. I like to the keep things as simple as possible and, ideally, reusable. At my previous employment I came up with a method of validation, but I was never entirely happy with the results. Some of the code repeated itself, and it was difficult to extend to arrays and array comparison. So, I went back to the drawing board building on top of the ideas that I created with the first validation library I created.