Skip to content

Commit 9bc59d1

Browse files
initial
0 parents  commit 9bc59d1

File tree

8 files changed

+97
-0
lines changed

8 files changed

+97
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*.class
2+
*.log
3+
4+
# sbt specific
5+
.cache/
6+
.history/
7+
.lib/
8+
dist/*
9+
target/
10+
lib_managed/
11+
src_managed/
12+
project/boot/
13+
project/plugins/project/
14+
15+
# Scala-IDE specific
16+
.scala_dependencies
17+
.worksheet
18+
.idea
19+
20+
.DS_Store
21+
.bloop
22+
.metals

build.sbt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
2+
3+
name := "scala-sql-formatter"
4+
5+
scalaVersion in ThisBuild := "2.12.8"
6+
7+
lazy val root =
8+
crossProject(JSPlatform, JVMPlatform).
9+
crossType(CrossType.Full).in(file(".")).
10+
settings(
11+
name := "scala-sql-formatter",
12+
version := "0.1-SNAPSHOT"
13+
).
14+
jvmSettings(
15+
libraryDependencies += "com.github.vertical-blank" % "sql-formatter" % "1.0"
16+
).
17+
jsSettings(
18+
jsDependencies += "org.webjars.npm" % "sql-formatter" % "2.3.3" / "2.3.3/dist/sql-formatter.js" commonJSName "sqlFormatter",
19+
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
20+
).
21+
configs(IntegrationTest).
22+
settings(Defaults.itSettings: _*).
23+
settings(libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.8" % IntegrationTest).
24+
settings(
25+
unmanagedSourceDirectories in IntegrationTest ++=
26+
CrossType.Full.sharedSrcDir(baseDirectory.value, "it").toSeq
27+
).
28+
jsSettings(inConfig(IntegrationTest)(ScalaJSPlugin.testConfigSettings): _*)
29+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.vertical_blank.sqlformatter.scala
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSImport
5+
6+
@js.native
7+
@JSImport("sql-formatter", JSImport.Namespace)
8+
object Facade extends js.Object {
9+
def format(obj: js.Any): String = js.native
10+
}
11+
12+
object SqlFormatter {
13+
def format(sql: String): String = Facade.format(sql)
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.vertical_blank.sqlformatter.scala
2+
3+
object SqlFormatter {
4+
def format(sql: String): String = com.github.vertical_blank.sqlformatter.SqlFormatter.format(sql)
5+
}

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.2.1

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.29")
2+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
# scala-sql-formatter
3+
4+
SQL Formatter for Scala.
5+
6+
- On jvm, calls [https://github.com/vertical-blank/sql-formatter](https://github.com/vertical-blank/sql-formatter)
7+
- On js, calls [https://github.com/zeroturnaround/sql-formatter](https://github.com/zeroturnaround/sql-formatter)
8+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.vertical_blank.sqlformatter.scala
2+
3+
import org.scalatest.FunSuite
4+
5+
class Test extends FunSuite {
6+
7+
test("Call SqlFormatter") {
8+
val formatted = """|SELECT
9+
| *
10+
|FROM
11+
| table1""".stripMargin
12+
13+
assert(SqlFormatter.format("SELECT * FROM table1") == formatted)
14+
}
15+
16+
}

0 commit comments

Comments
 (0)