jonifreeman / sqltyped Goto Github PK
View Code? Open in Web Editor NEWEmbedding SQL as an external DSL into Scala
License: Apache License 2.0
Embedding SQL as an external DSL into Scala
License: Apache License 2.0
Using PostgreSQL. Driver: postgresql-42.0.0.jar. I built by project using SBT "hello" and working my way from there. Also using sbt-eclipse to create Eclipse project definitions (added system properties to eclipse.ini, added the driver's jar file to my system's PATH variable for it to be able to find the PostgreSQL driver). I'm trying to use Eclipse to run my project, but the same happens using SBT from console. I'm quite the noob, but I've tried collecting as much info as possible.
The database is hosted locally and is called tut_sqltyped1, with a schema named public. Doesn't matter if I omit the schema property or not.
SBT build:
import Dependencies._
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "dk.stldev.tut",
scalaVersion := "2.11.8",
version := "0.1.0-SNAPSHOT",
crossScalaVersions := Seq("2.12.2", "2.11.0")
)),
name := "Hello",
libraryDependencies += scalaTest % Test,
libraryDependencies += "fi.reaktor" % "sqltyped_2.11" % "0.4.3"
)
initialize ~= { _ =>
System.setProperty("sqltyped.url", "jdbc:postgresql://localhost:5432/tut_sqltyped1")
System.setProperty("sqltyped.driver", "org.postgresql.Driver")
System.setProperty("sqltyped.username", "postgres")
System.setProperty("sqltyped.password", "todoroot")
}
Is there any chance shapeless can be "embedded" under the sqltyped package so as to allow the use with libraries dependent on shapeless 1.x? (ie, spray uses shapeless 1.x and there is little chance it well get upgraded anytime soon.)
Any SQL functions like distinct, count, etc. (and maybe others) cause the following error because the default dataTypes list is empty:
exception during macro expansion:
[error] java.lang.UnsupportedOperationException: empty.reduceLeft
[error] at scala.collection.LinearSeqOptimized$class.reduceLeft(LinearSeqOptimized.scala:124)
[error] at scala.collection.immutable.List.reduceLeft(List.scala:84)
[error] at sqltyped.SqlParser$class.dataType(parser.scala:168)
I can't seem to get this to compile.
Code:
val q = sql("select * from users") // two columns: "name" and "comment"
println("1 Query: "+q.sql)
println("Returns: ")
q() map (_ get "name") // won't compile
Error message:
value get is not a member of shapeless.::[String with shapeless.labelled.KeyTag[String("name"),String],shapeless.::[String with shapeless.labelled.KeyTag[String("comment"),String],shapeless.HNil]]
Hello,
I would like to use sqltyped with Liftweb framework. However there is no build.scala file, only build.sbt.
I have added sqltyped to the dependencies, but there is an error when I use 'sql' command. For example;
val personNames = sql("SELECT name FROM person")
And the error is;
System property 'sqltyped.url is required to get a compile time connection to the database
Please suggest me how to do this. Thank you.
Hi,
I installed typesafe stack and in demo dir dir "sbt run"
following are results
warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: fi.reaktor#sqltyped-json4s_2.10.0;0.1.0: not found
[warn] :: com.typesafe#slick_2.10.0;1.0.0-RC1: not found
[warn] :: net.databinder#unfiltered_2.10.0;0.6.4: not found
[warn] :: net.databinder#unfiltered-netty_2.10.0;0.6.4: not found
[warn] :: net.databinder#unfiltered-netty-server_2.10.0;0.6.4: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[error] {file:/shared/sqltyped/demo/}sqltyped-demo/*:update: sbt.ResolveException: unresolved dependency: fi.reaktor#sqltyped-json4s_2.10.0;0.1.0: not found
[error] unresolved dependency: com.typesafe#slick_2.10.0;1.0.0-RC1: not found
[error] unresolved dependency: net.databinder#unfiltered_2.10.0;0.6.4: not found
[error] unresolved dependency: net.databinder#unfiltered-netty_2.10.0;0.6.4: not found
[error] unresolved dependency: net.databinder#unfiltered-netty-server_2.10.0;0.6.4: not found
[error] Total time: 45 s, completed Jan 7, 2013 7:04:01 PM
I have a commit right now which constructs records with symbols as keys instead of strings. This has advantages as some of the operations for e.g. converting to/from case classes use symbols instead of Strings. OTOH it seems that using symbols significantly degrades performance.
I was wondering whether you have had observations on Strings vs. symbols since you've chosen to use Strings and operations with symbols seem to have been available as of Shapeless 2.0 already.
If it's about performance vs. convenience, I'm also wondering on whether this should be somehow configurable. However it's currently not possible to combine different configurations like useInputTags, keys, jdbcOnly and being globally configurable might not be flexible enough. Perhaps it's worth it to expose these flags as a user might like to e.g. have a jdbcOnly, keys and symbols-as-keys settings.
Currently using a schema to qualify the table name e.g. "SELECT * FROM schema.table" doesn't work. The parser is actually the easy part, if I just parse and ignore the schema, I get an error message of the kind "Unknown table XXX". It seems that this is because only data about the current schema is being loaded. If this is the case, what strategies might be used to get all relevant schemas? All? Lazily load the schema on first encounter? Configure schemas to load in a config file?
Currently sqltyped has several macros, each serving to pass a separate boolean parameter to the implementation: sqlj passes "jdbcOnly", sqlt passes "useInputTags" and sqlk passes "keys". I'm also wondering whether it's useful to have an option of using symbols as keys (#13) and interpolation as parameters (#14). In this case each new boolean parameter means an exponential number of combinations, leading to either too many abbreviations, e.g. sqljkt, which seems crazy, or missed combinations, e.g. I can't currently have jdbcOnly with keys, which seems like a reasonable combination. I'm wondering which other options to pass configurations you've thought about:
Obviously sqltyped is using the first 2 options, have you looked at macro annotations and if yes, do you know of any show-stoppers for using it?
Some of the benefits of using String interpolation for queries is that one doesn't have to track the number and positions of params making it easier to develop, refactor and maintain. sqltyped is already using interpolation for SQL fragments. It might be worth it to implement both. For instance both Slick and Anorm use $
for parameter interpolation and #$
for "string splicing".
Any arguments for/against?
Hi All, is sqltyped still actively maintained ?
Thanks
I have been playing with introducing a naming strategy for field names. If a query falls back to jdbc on Oracle, it produces something like "USER_ID" for the field name. A String -> String naming strategy would let the programmer turn that into "userId" by splitting on [^a-zA-Z], toLowerCase, title casing the tail and rejoining with empty string. Anything they want. An organization may want to whitelist "id" to be uppercase so the field in their case is "userID".
What do you think about this?
sbt compile
...
sbt.ResolveException: unresolved dependency: org.json4s#json4s-native_2.10;3.1.0-SNAPSHOT: not found
I think the dependency
"org.json4s" %% "json4s-native" % "3.1.0-SNAPSHOT"
in the build.scala needs to get updated to
"org.json4s" %% "json4s-native" % "3.1.0"
Hey there,
count(1) works just fine. Behavior-wise, count(1) and count(*) should be identical. Here is the stack trace for a couple of lines or so:
[info] Compiling 1 Scala source to /target/scala-2.10/classes...
[error] /src/main/scala/app/utils/net/Database.scala:19: exception during macro expansion:
[error] java.lang.RuntimeException: Term AllColumns(Table(groups,None)) not supported
[error] at scala.sys.package$.error(package.scala:27)
[error] at sqltyped.Typer.tpeOf(typer.scala:309)
[error] at sqltyped.TypeSigDSL$$anon$2.tpe(typesigdsl.scala:50)
...
[error] if (sql("select count(*) from foo").apply == 0) {
[error] ^
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.