DSL for SqlBulkInsert

27 views
Skip to first unread message

Adam Tybor

unread,
Aug 27, 2008, 4:16:09 PM8/27/08
to Rhino Tools Dev
So I started writing a dsl for SqlBulkInsert, its nothing fancy right
now.

sqlBulkInsert "test", "People", TableLock = true :
schema:
TableSchema["id"] = int
TableSchema["FirstName"] = string
TableSchema["LastName"] = string
TableSchema["email"] = string
map:
Mappings["id"] = "id"
Mappings["firstname"] = "firstname"
Mappings["lastname"] = "lastname"
Mappings["email"] = "email"
Mappings["id"] = "userid"

I would like to get rid of the child macros schema and map and just
create a new macro map to do the mappings.

sqlBulkInsert "test", "People" :
map "id", int
map "firstname"
map "lastname"
map "email"
map "id", int, "userid"

I am just not certain how to expand the map macro in the body of the
sqlBulkInsert macro. I intend to have a method MapColumn on the
ConventionSqlBulkInsert class. I would simply like to expand the map
macro to process the arguments and create the proper method invocation
to the MapColumn function of the sqlBulkInsert base class.

Does that make sense? Can someone point me into the right direction?

Thanks,
Adam

Nathan Stott

unread,
Aug 27, 2008, 4:43:29 PM8/27/08
to rhino-t...@googlegroups.com
If you make the "Map" method on the base class take the appropriate
arguments and have the appropriate uploads, you have no need to expand
a macro at all.

Nathan Stott

unread,
Aug 27, 2008, 4:43:51 PM8/27/08
to rhino-t...@googlegroups.com
Note that in my last message I meant to say appropriate "overloads"
not "uploads" :).

Adam Tybor

unread,
Aug 27, 2008, 5:47:32 PM8/27/08
to Rhino Tools Dev
Thanks Nathan, I new that would work but I would rather have a more
terse syntax without all the overloads.

sqlBulkInsert "test", "People", TableLock = true :
MapColumn("id", int)
MapColumn("firstname")
MapColumn("lastname")
MapColumn("email")
MapColumn("userid", "id", int)

While the above works I would much rather see

map userid, id, int

I just committed this, we will see what else I can come up with over
the next couple days after I work with the macros a little more.

Ayende, any ideas?

Adam

On Aug 27, 3:43 pm, "Nathan Stott" <nrst...@gmail.com> wrote:
> Note that in my last message I meant to say appropriate "overloads"
> not "uploads" :).
>
>
>
> On Wed, Aug 27, 2008 at 3:43 PM, Nathan Stott <nrst...@gmail.com> wrote:
> > If you make the "Map" method on the base class take the appropriate
> > arguments and have the appropriate uploads, you have no need to expand
> > a macro at all.
>
> >> Adam- Hide quoted text -
>
> - Show quoted text -

Nathan Stott

unread,
Aug 27, 2008, 6:25:26 PM8/27/08
to rhino-t...@googlegroups.com
You can just call the method on your base class "map" and you don't
have to put parenthesis for method calls in boo.

It works...

Adam Tybor

unread,
Aug 27, 2008, 6:35:19 PM8/27/08
to Rhino Tools Dev
Yeah that works but I have to make the method name lower case.
> > - Show quoted text -- Hide quoted text -

Nathan Stott

unread,
Aug 27, 2008, 7:33:20 PM8/27/08
to rhino-t...@googlegroups.com
Use a transformer to make it uppercase. Register a compiler step that
checks symbols to see if they match "map" with the appropriate
arguments and if so, then make it uppercase.

Adam Tybor

unread,
Aug 28, 2008, 9:08:45 AM8/28/08
to Rhino Tools Dev
Thanks for the help Nathan. Here is the solution I just checked-in
which I think works pretty well and was easy to implement. I went
down the road of looking at a CompilerStep but ensuring I had the
right context was a little cumbersome, espically considering map is
already a boo builtin. This was my first time really working with the
boo compiler so it took a little bit to understand the ast, but once I
figured it out the solution is pretty trivial.

public override Statement Expand(MacroStatement macro)
{
if (macro.Block != null)
{
foreach(Statement statement in macro.Block.Statements)
{
if (IsMappingStatement(statement))
{
MethodInvocationExpression mappingCall =
GetMappingStatement(statement);
mappingCall.Target = new
ReferenceExpression("MapColumn");
}
}
}
return base.Expand(macro);
}

Thanks again for the help,
Adam

Ayende Rahien

unread,
Aug 28, 2008, 9:19:38 AM8/28/08
to rhino-t...@googlegroups.com
I have issue with GetMappingStatement returning an expression, but that about it, a good approach.

Nathan Stott

unread,
Aug 28, 2008, 11:18:50 AM8/28/08
to rhino-t...@googlegroups.com
Good job. If this was your first time working with the AST, you
picked it up quickly. It's very elegant isn't it?
Reply all
Reply to author
Forward
0 new messages