sql-formatter

SQL Formatter for Scala

License

License

MIT
Categories

Categories

ORM Data
GroupId

GroupId

com.github.takayahilton
ArtifactId

ArtifactId

sql-formatter_sjs1_2.11
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

sql-formatter
SQL Formatter for Scala
Project URL

Project URL

https://github.com/takayahilton/sql-formatter
Project Organization

Project Organization

com.github.takayahilton
Source Code Management

Source Code Management

https://github.com/takayahilton/sql-formatter

Download sql-formatter_sjs1_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.takayahilton/sql-formatter_sjs1_2.11/ -->
<dependency>
    <groupId>com.github.takayahilton</groupId>
    <artifactId>sql-formatter_sjs1_2.11</artifactId>
    <version>1.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.takayahilton/sql-formatter_sjs1_2.11/
implementation 'com.github.takayahilton:sql-formatter_sjs1_2.11:1.2.1'
// https://jarcasting.com/artifacts/com.github.takayahilton/sql-formatter_sjs1_2.11/
implementation ("com.github.takayahilton:sql-formatter_sjs1_2.11:1.2.1")
'com.github.takayahilton:sql-formatter_sjs1_2.11:jar:1.2.1'
<dependency org="com.github.takayahilton" name="sql-formatter_sjs1_2.11" rev="1.2.1">
  <artifact name="sql-formatter_sjs1_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.takayahilton', module='sql-formatter_sjs1_2.11', version='1.2.1')
)
libraryDependencies += "com.github.takayahilton" % "sql-formatter_sjs1_2.11" % "1.2.1"
[com.github.takayahilton/sql-formatter_sjs1_2.11 "1.2.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
org.scala-js : scalajs-library_2.11 jar 1.1.1

test (2)

Group / Artifact Type Version
org.scala-js : scalajs-test-bridge_2.11 jar 1.1.1
org.scalatest : scalatest_sjs1_2.11 jar 3.2.0

Project Modules

There are no modules declared in this project.

sql-formatter

Build Status Maven Central codecov.io Scala.js Scala.js

Scala port of great SQL formatter https://github.com/zeroturnaround/sql-formatter, https://github.com/vertical-blank/sql-formatter.

Written with only Scala Standard Library, without dependencies.

Demo

Usage

Scala (on JVM)

libraryDependencies += "com.github.takayahilton" %% "sql-formatter" % "1.2.1"

Scala.js

libraryDependencies += "com.github.takayahilton" %%% "sql-formatter" % "1.2.1"

Scala Native

libraryDependencies += "com.github.takayahilton" %%% "sql-formatter" % "1.2.1"

Examples

You can easily use com.github.takayahilton.sqlformatter.SqlFormatter :

import com.github.takayahilton.sqlformatter._

SqlFormatter.format("SELECT * FROM table1")

This will output:

SELECT
  *
FROM
  table1

Dialect

You can pass dialect name to SqlFormatter.of :

import com.github.takayahilton.sqlformatter._

SqlFormatter.of(SqlDialect.CouchbaseN1QL).format("SELECT *")

Currently just four SQL dialects are supported:

Format

Defaults to two spaces. You can pass indent string to format :

import com.github.takayahilton.sqlformatter._

SqlFormatter.format(
  "SELECT * FROM table1",
  indent = "    ")

This will output:

SELECT
    *
FROM
    table1

Placeholders replacement

You can pass Seq or Map to format :

import com.github.takayahilton.sqlformatter._

// Named placeholders
SqlFormatter.format("SELECT * FROM tbl WHERE foo = @foo", params = Map("foo" -> "'bar'"))

// Indexed placeholders
SqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", params = Seq("'bar'"))

Both result in:

SELECT
  *
FROM
  tbl
WHERE
  foo = 'bar'

Versions

Version
1.2.1
1.2.0
1.1.0
1.0.0
0.1.0