Skip to content

Commit

Permalink
Fix #11: dsl parser detects functions upper, lower, to_tsvector
Browse files Browse the repository at this point in the history
… only if they ends with brace `(`
  • Loading branch information
caiiiycuk committed Jan 23, 2023
1 parent d15e57c commit f3348b0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Build extends Build {
lazy val project = Project("root", file("."), settings = Seq(
name := "postgresql-to-sqlite",
organization := "com.github.caiiiycuk",
version := "0.0.1-SNAPSHOT",
version := "1.0.1",
scalaVersion := "2.11.12",

libraryDependencies ++= Seq(
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/github/caiiiycuk/pg2sqlite/dsl/DSL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class DSL(line: String) {
partials match {
case head :: _ if head.startsWith("constraint") =>
None
case head :: _ if head.startsWith("to_tsvector") =>
case head :: _ if head.startsWith("to_tsvector(") =>
val name = columnDefenition.takeBraces.head.tokens.last
Some(Column(name, None))
case head :: _ if head.startsWith("lower") || head.startsWith("upper") =>
case head :: _ if head.startsWith("lower(") || head.startsWith("upper(") =>
val name = columnDefenition.takeBraces.head.tokens.head
Some(Column(name, None))
case head :: sqlType :: _ =>
Expand Down
57 changes: 57 additions & 0 deletions src/test/scala/com/github/caiiiycuk/pg2sqlite/dsl/DumperTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.caiiiycuk.pg2sqlite.dsl

import com.github.caiiiycuk.pg2sqlite.iterator.Line
import com.github.caiiiycuk.pg2sqlite.{Connection, DumpInserter}
import org.scalatest.{BeforeAndAfter, FlatSpec, Matchers}

import java.io.File

class DumperTest extends FlatSpec with Matchers with BeforeAndAfter {

val dbFile = new File("test.db")

private def makeConnection() = {
if (dbFile.exists()) {
dbFile.delete()
}

Connection.sqlite(dbFile)
}

after {
new File("test.db").delete()
}

"dumper" should "generate db from test-case of issue#11" in {
val connection = makeConnection()
val inserter = new DumpInserter(connection)
val dump =
"""
|CREATE TYPE product_type AS ENUM (
| 'Material',
| 'Digital'
|);
|
|CREATE TABLE product (
| client_id integer NOT NULL,
| order_product integer,
| upper_price integer NOT NULL,
| lower_price integer NOT NULL,
| type product_type NOT NULL,
| product_id integer NOT NULL--,
| CONSTRAINT product_check CHECK (((lower_price > upper_price) AND (upper_price <= 200))),
| CONSTRAINT product_order_product_check CHECK ((order_product > 0)),
| CONSTRAINT product_upper_price_check CHECK ((upper_price >= 0))
|);
|""".stripMargin
.split("\n")
.zipWithIndex
.map {
case (text, num) =>
Line(num, text)
}

inserter.insert(dump.iterator)
connection.close
}
}

0 comments on commit f3348b0

Please sign in to comment.