Skip to content

Example of an implementation of SQL as a DSL in scala

Notifications You must be signed in to change notification settings

dannylagrouw/scala-sql-dsl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scala SQL DSL

Scala implementation of a really small subset of the SQL language

To understand how to write internal DSLs in Scala I started implementing a small subset of the SQL language.

Implemented:

  • select operation with fields
  • where clause with (typed) equals, in, and, or
  • order
  • A ‘renderer’ to create a SQL String from the given Query object

Scala SQL DSL lets you write stuff like:

scala> val q = select ("*") from ("user") where (("name","peter") and (("active", true) or ("role", "admin")))
scala> q.sql
res0: java.lang.String = select * from user where (name = 'peter' and (active = true or role = 'admin'))

Prerequisites

  • buildr 1.4.0
  • scala 2.8.0.r19281-b20091026023411 (should work with more recent versions as well)

Usage

The spec contains various examples on how to write queries. But basically you start by:

  • Import all functions/implicits in the QueryBuilder object: import QueryBuilder._
  • Import the AnsiSqlRenderer object: AnsiSqlRenderer._

Author

Written by Peter Maas

License

This software is licensed under the Apache 2 license, quoted below.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.

About

Example of an implementation of SQL as a DSL in scala

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%