News for hackers. Stuff that matters.
Re:Slick: a modern database query and access library for Scala by boyter on Tuesday August 07, 2012 @07:56PM (#4353057)
The problem I can see is that its not totally type safe as you still need to run the code to check that your entity is compatible with the underlying table at runtime. If I am wrong here please correct me. It appears fairly easy to make a mistake on the datatype (Int vs Long) and have it blow up in your face when you run it. Sure the re-factoring is simple but I don't want to wait till runtime to catch these issues.

I don't think that its not achievable either. I think that LINQtoSQL and EntityFramework are the best implementation of database access that exists today. Import the database/table select over it with 95% assurance that the query will work at runtime and with the correct types. I really wish something like this existed in the Java world as I would switch in a heartbeat.

For the record I code C# mostly in my day job, but every time I move over to PHP/Java/Scala I miss LINQ. I am working with Play! at the moment and while the DB access is the best I have come across in the Java world, its still not at the same standard. I am still getting issues with simple selects where I should be using a Long rather then an Int.

Re:Slick: a modern database query and access library for Scala by RasputinJones2 on Tuesday August 07, 2012 @10:38PM (#4353586)
>> The problem I can see is that its not totally type safe as you still need to run the code to check that your entity is compatible with the underlying table at runtime. If I am wrong here please correct me.

With pleasure. You are wrong. SLICK (formerly known as ScalaQuery) is Typesafe.

>> I am working with Play! at the moment and while the DB access is the best I have come across in the Java world

I've been working with Scalaquery with Play 2 for two months now. The experience has been fantastic. I haven't really had any queries I haven't been able to create even complex joins.

The approach where queries are made like Scala collections is really intuitive. Compared to you I just started using linq recently for a work related project. Basically coming from the other end and I've been quite pleased that the SQ skills I've built over the past month transferred over reasonably well. I only have good things to say about Slick. You should try it out.

Re:Slick: a modern database query and access library for Scala by boyter on Wednesday August 08, 2012 @02:26AM (#4354243)
Its only typesafe if you generate against the database though correct? Its entirely possible for me to write it by hand, and not know there is a problem till runtime yes? I want to close this loop, and LINQ is the only db access I have tried that does so.

Should have mentioned I am using Scala for the DB access in Play 2.0 and the other portions are mostly Java (heavy lifting done in existing libraries, so its just plumbing work hence doing it in Java). I am pretty happy with it except I still hit type issues which I would never encounter in LINQ.

I guess the way im looking at it is that LINQ solved a pain point for me which I am still experiencing in other languages. I would very much like someone to take the pain away from me, either by getting C# working well on Linux or bringing some of the features from C# over into the Java world.

Re:Slick: a modern database query and access library for Scala by wheaties on Tuesday August 07, 2012 @09:45PM (#4353438)
Yes and no. I'm building a library that allows you to at least pull in the database structure and have the code auto-generated so that your code agrees with the schema. You can see it here: http://wheaties.github.com/Squealer/

After that, if your production schema is that different from your development schema that auto-generated code can't help, then you've got more problems than that.

Re:Slick: a modern database query and access library for Scala by boyter on Tuesday August 07, 2012 @10:13PM (#4353512)
Looks good.

I know that issues where the schema is different are always going to be a problem (nothing can save you there unless you want auto generated entities every time) but I can live with that.

How are you dealing with issues like the one I found the other day.

A view was created in MySQL which selected from a table with a column compressed with the compress function and was uncompressed in the view.

IE

select id,uncompress(content) as content from stuff;

The above looks fine, but unless you cast the content to a char most ORM's have issues working out what it is, yet it looks fine in your standard mysql command line query. It's an unusual case, but I would like to see the autogenerated code produce a binary cast so I can explicitly see the error when I generate rather then at runtime.

Re:Slick: a modern database query and access library for Scala by wheaties on Tuesday August 07, 2012 @10:18PM (#4353526)
That, unforunately, I can't help with. Like any SQL DSL I've worked with, there's a few features that still aren't fleshed out... yet. I have complete faith they will flesh them out if prompted by the community. After that, you'll have to use pure SQL and cross your fingers.
Re:Slick: a modern database query and access library for Scala by boyter on Wednesday August 08, 2012 @02:28AM (#4354245)
Oh well. If its decent enough I can live with this single issue as I catch it pretty easily though integration tests.
Re:Slick: a modern database query and access library for Scala by saryant on Thursday August 09, 2012 @05:17PM (#4363286)
Sounds like you and I are in the same position.

I absolutely agree that LINQ has no peer in the open source world. I too am a .NET/C# dev by day but I've been playing around a lot with the Play! framework on my own time (built the UI to my senior thesis in it) and I much prefer their ANORM over a bastardized ORM that only half-works.

Re:Slick: a modern database query and access library for Scala by jzoidberg on Tuesday August 07, 2012 @09:47PM (#4353440)
It looks like the DB schema is generated from the class definitions by the library. Queries are type safe: http://slick.typesafe.com/doc/0.11.0/gettingstarted.html#sch...
Re:Slick: a modern database query and access library for Scala by boyter on Tuesday August 07, 2012 @10:14PM (#4353520)
That's OK, but I would still like to do it the other way. Where the code is generated from the DB. Might just be my mindset but I prefer to work in the DB tool and then layer the application on top.
Re:Slick: a modern database query and access library for Scala by szeiger on Wednesday August 08, 2012 @06:53AM (#4354887)
This will be one of the big topics for us for the next months. We are planning to add type macros to Scala (in addition to the def macros that are already available as an experimental feature in the 2.10 milestones) and use them to generate types representing database schemas directly from the database. The idea is to have the compiler connect to a live database during development and a way to freeze the generated types at some point in the form of standalone Scala source which does not need a database any more for compilation.