The TypeSql project is hosted on GitHub TypeSql is a compiler. It compiles annotated SQL into strongly-typed data-access-objects. The inspiration was TypeScript. But don't try to take the analogy too far. TypeScript takes annotated javascript and compiles it into plain javascript. Its primary purpose is verification. TypeSQL takes annotated SQL and compiles it into a different, general-purpose programming language (C# only, for the moment). Our primary purpose is for you to write less code. Less code means less bugs and more functionality. It means you can ask for more money and go home earlier. Your family will love you more, and you will live longer. Are you talking to me?Do you believe that a strongly-typed, object-orientated programming language is the best way to write applications? Do you believe that SQL is still the best language for querying relational databases? Good for you. Here at TypeSql HQ, we feel the same. Bridging the O-O relational-databases divide has been attempted many times, in many ways. Frankly, we don't love any of them. Here's our wish-list:
The closest we've found are micro-ORMs (eg. Dapper). Our issue with using these is how to manage the classes created to hold query results (we like types, remember). In a large application, it is not uncommon for many queries to differ only slightly in the results they return. Which tends to lead to either: Class explosion
or Super DTO!One class that contains all possible properties that can be returned. Consumers of the class accessing, say So that's where we're coming from. I already have [insert ORM of choice], why do I need TypeSql?Maybe you don't. If your team is happy and productive using ORM X, then carry on. Full-service ORMs like Entity Framework andNHibernate are cruise-ships; TypeSQL is a surfboard. We just want to make travelling through the water a little easier and more fun. They do their best to hide the fact the ocean even exists (until the abstraction leaks, and sinks the ship...forgive me). But seriously, we approach the problem from different angles. TypeSql knows nothing about your database schema, and why should it? We care about the shape of the data you are retrieving, not the shape the data is stored. That is the fundamental difference. EF & friends map things that live in the database (like tables, views, and stored-procedures) to objects. They then attempt to translate interactions with those objects (ie. accessing properties and calling methods) into the appropriate SQL (this often happens at runtime). With TypeSQL, youwrite your SQL (plus a few annotations), and at compile time the SQL is translated to data-access objects that represent your query(not stuff that lives in the database). EF & friends also deal with concerns like caching and object-identity; TypeSql does not. Show me some code!Here's how it works. We have some data in our relational DB. We want to query it. We write our parameterised SQL ( let's suppose its in a file called 'TurtlesByColor.sql' ).
Now we annotate it with types.
Compile with TypeSql. This produces a class called
And a method:
The 'TurtlesByColorResult' class looks like:
Accessing your data then looks like:
AvailabilityCurrently, TypeSQL is available in C# flavor only. Hopefully, we will be coming soon to a language near you.
InstallationCurrently, the supported method for using TypeSql is via a VisualStudio extension in Visual Studio 2010 or Visual Studio 2012.
Type that SQL baby!
Its not you, its meThis is a work-in-progress. There are an infinite number of scenarios we have not thought of. We welcome your feedback. But please be gentle, our egos are fragile and we cry easily. PerformanceInternally, TypeSql uses Dapper for data-access. Its performance is effectively identical, which is itself effectively identical to raw ADO.NET. Checkout the benchmarks. CreditsTypeSql stands on the shoulders of two brilliant projects. ANTLRIf you need to parse text, ANTLR is your tool. Terence Parr has made language-recognition possible for mere mortals. And thanks to Sam Harwell for the C# version. DapperDapper has been called a micro-ORM. Whatever you call it, Sam Saffron and Marc Gravell have created a super-useful component. USAGEOutputsJust append the items in your SELECT list with the types you expect them to be. e.g
AggregatesYeah, you can do:
InputsType your input parameters like so:
Nullable typesSure.
NamespacesThe USING statement is used to import namespaces. See Enums section below for an example. EnumsYup. Say you have:
Then you can do:
|