JasonKleban / Unbounded

F# to T-SQL. Remote command execution and domain invariant enforcement
Apache License 2.0
3 stars 1 forks source link

Prototype Simple Expression to SQL Translator #1

Open sgoguen opened 9 years ago

sgoguen commented 9 years ago

I'd like to approach this library by tackling some simple problems first to get a sense of how difficult the larger problems will be. First thing I'd like to do is translate expressions and constructs that have a relatively clear 1-to-1 mapping. For example:

A simple add function:

let add x y = x + y

Should translate into the following SQL code:

create function [add](@x int, @y int)
returns int
as
begin
    return(@x + @y)
end

An object based expression like so:

type BandMember = { Name:string; Position:string; DOB:System.DateTime }

let george = { Name="George Clinton"; Position="bandleader"; DOB=new System.DateTime(1941, 7, 22) }

Might translate to:

select 'George' As Name, 'bandleader' As Position, cast('7/22/1941' as datetime) As DOB
ghost commented 9 years ago

Yes, this is a good goal.

For your first example, but way down the road, I was thinking that such functions would need to be inlined at runtime into the emitted SQL since the creation of locally scoped functions is not supported in the target language and we wouldn't necessarily want to (nor have permissions to) create new functions in support of an adhoc command.