Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/repair ontology #2

Merged
merged 25 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 75 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
val scala3Version = "3.4.0-RC4"
val mainVersion = "0.2.5"
val scala3Version = "3.4.1-RC1"
val mainVersion = "0.2.5"

Global / onChangedBuildSource := ReloadOnSourceChanges

ThisBuild / organization := "ru.primetalk"
ThisBuild / version := mainVersion
ThisBuild / scalaVersion := scala3Version
ThisBuild / organization := "ru.primetalk"
ThisBuild / version := mainVersion
ThisBuild / scalaVersion := scala3Version
ThisBuild / versionScheme := Some("early-semver")

// scalacOptions ++= Seq(
Expand All @@ -27,20 +27,21 @@ val catsEffect = "org.typelevel" %% "cats-effect" % "3.5.0"
val catsCore = "org.typelevel" %% "cats-core" % "2.9.0"
val fs2 = libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "3.7.0",
"co.fs2" %% "fs2-io" % "3.7.0",
"co.fs2" %% "fs2-io" % "3.7.0"
)

val commonSettings = Seq(
scalaVersion := scala3Version,
scalacOptions ++= Seq(
//"-Xmax-inlines=50",
"-deprecation",
// "-Xmax-inlines=50",
"-deprecation"
),
libraryDependencies ++= Seq(
catsCore,
"com.novocode" % "junit-interface" % "0.11" % Test,
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test,
"org.scalatest" %% "scalatest" % "3.2.15" % Test,
//"io.github.kitlangton" %% "quotidian" % "0.0.9",
"com.novocode" % "junit-interface" % "0.11" % Test,
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test,
"org.scalatest" %% "scalatest" % "3.2.15" % Test
)
)

Expand All @@ -49,11 +50,11 @@ lazy val root = (project in file("."))
typedOntologyMetaMeta,
typedOntologyMeta,
typedOntologySimpleMeta,
ontologyExample1,
ontologyExample1
)
.settings(
name := "typed-ontology",
publish / skip := true,
name := "typed-ontology",
publish / skip := true
)
//lazy val typeSet = project
// .in(file("type-set"))
Expand All @@ -66,34 +67,85 @@ lazy val typedOntologyMetaMeta = project
.in(file("typed-ontology-metameta"))
.settings(
name := "typed-ontology-metameta",
fs2,
fs2
)
.settings(commonSettings *)
.settings(commonSettings*)

lazy val typedOntologyMeta = project
.in(file("typed-ontology-meta"))
.settings(
name := "typed-ontology-meta",
name := "typed-ontology-meta"
)
.dependsOn(typedOntologyMetaMeta)
.settings(commonSettings :_*)
.settings(commonSettings: _*)

lazy val typedOntologySimpleMeta = project
.in(file("typed-ontology-simple-meta"))
.settings(
name := "typed-ontology-simple-meta",
name := "typed-ontology-simple-meta"
)
.dependsOn(typedOntologyMetaMeta)
.settings(commonSettings *)
.settings(commonSettings*)

lazy val ontologyExample1 = project
.in(file("ontology-example1"))
.settings(
name := "ontology-example1",
publish / skip := true,
name := "ontology-example1",
publish / skip := true
)
.dependsOn(
typedOntologySimpleMeta,
typedOntologyMetaMeta
)
.settings(commonSettings*)

val quillVersion = "4.8.1"

lazy val ontologyQuillParser = project
.in(file("ontology-quill-parser"))
.settings(
name := "ontology-quill-parser",
publish / skip := true
)
.dependsOn(
typedOntologySimpleMeta,
typedOntologyMetaMeta
)
.settings(commonSettings*)
.settings(
libraryDependencies ++= Seq(
// postgres driver
"org.postgresql" % "postgresql" % "42.7.0",
// Syncronous JDBC Modules
"io.getquill" %% "quill-jdbc" % quillVersion,
)
)

lazy val ontologyQuill = project
.in(file("ontology-quill"))
.settings(
name := "ontology-quill",
publish / skip := true
)
.dependsOn(
typedOntologySimpleMeta,
typedOntologyMetaMeta,
ontologyQuillParser
)
.settings(commonSettings*)
.settings(
libraryDependencies ++= Seq(
// postgres driver
"org.postgresql" % "postgresql" % "42.7.0",
// Syncronous JDBC Modules
"io.getquill" %% "quill-jdbc" % quillVersion,
// // Or ZIO Modules
// "io.getquill" %% "quill-jdbc-zio" % quillVersion,
// // Or Cassandra
// "io.getquill" %% "quill-cassandra" % quillVersion,
// // Or Cassandra + ZIO
// "io.getquill" %% "quill-cassandra-zio" % quillVersion,
// // Add for Caliban Integration
// "io.getquill" %% "quill-caliban" % quillVersion
)
)
.settings(commonSettings *)
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,64 @@ package ru.primetalk.typed.ontology.example1
import ru.primetalk.typed.ontology.simple.meta._
import ru.primetalk.typed.ontology.metameta.OntologyType.Record
import java.time.LocalDateTime
import SimpleTypes.{given, *}

object Product extends TableBuilder:
object id extends column[Int]
val id1 = id
type Id = id1.type
//type Id = id.type // Scala 3 bug
object name extends column[String]
val name1 = name
type Name = name1.type
object price extends column[BigInt]

type TableSchema = id.type #: name.type #: price.type #: EmptySchema
type Price = price.type
type PriceSchema = Price #: EmptySchema
type NamePriceSchema = Name #: Price #: EmptySchema
type TableSchema = Id #: Name #: Price #: EmptySchema
val tableSchema: TableSchema = fields(id, name, price)
val idNameSchema = fields(id, name)
val primaryKeySchema = fields(id)
val namePriceSchema = fields(name, price)
type PrimaryKeySchema = id.type #: EmptySchema
val primaryKeySchema: PrimaryKeySchema = fields(id)

val fullSchema = infer[TableSchema]
val svt = summon[SchemaValueType.Aux1[TableSchema]]
type Row = svt.Value

object Order extends TableBuilder:
object id extends column[Int]
val id1 = id
type Id = id1.type
object date extends column[LocalDateTime]
type TableSchema = id.type #: date.type #: EmptySchema
type Date = date.type
type TableSchema = Id #: Date #: EmptySchema
val tableSchema: TableSchema = fields(id, date)
val ts = fields(id, date)
type TS = ts.Type
val svt = summon[SchemaValueType.Aux1[TableSchema]]
type Row = svt.Value

object OrderItem extends TableBuilder:
object id extends column[Int]
val id1 = id
type Id = id1.type
object orderId extends column[Int]
type OrderId = orderId.type
object productId extends column[Int]
type ProductId = productId.type
// val productId = Product.id// does not work well with toString

type TableSchema = id.type #: orderId.type #: productId.type #: EmptySchema
val tableSchema = infer[TableSchema]
type TableSchema = Id #: OrderId #: ProductId #: EmptySchema

val tableSchema: TableSchema = fields(id, orderId, productId)
// val tableSchema = infer[TableSchema]
// val tableSchema: TableSchema = id #: orderId #: productId #: EmptySchema

type SmallerSchema = id.type #: orderId.type #: EmptySchema
type SmallerSchema = Id #: OrderId #: EmptySchema
val smallerSchema: SmallerSchema = infer[SmallerSchema]

lazy val orderIdFk = orderId.foreignKey(Order.id)
lazy val productIdFk = productId.foreignKey(Product.id)
val svt = summon[SchemaValueType.Aux1[TableSchema]]
type Row = svt.Value
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ package ru.primetalk.typed.ontology.example1
import org.junit.Test
import ru.primetalk.typed.ontology.simple.meta._
import ru.primetalk.typed.ontology.metameta.OntologyType.Record
import SimpleTypes._
// class PersonSpec:

class PersonSpec:
// abstract final class Person

abstract final class Person
// object personProps extends RecordSchemaBuilder[Person]:
// val name = property[String]("name")
// val age = property[Int]("age") // : SimplePropertyId[Record[Person], Int]
// val title = property[String]("title")
// val baseSchema = fields(age, name)

object personProps extends RecordSchemaBuilder[Person]:
val name = property[String]("name")
val age = property[Int]("age") // : SimplePropertyId[Record[Person], Int]
val title = property[String]("title")
val baseSchema = fields(age, name)
// @Test def schemaTest =
// println(personProps.baseSchema)
// val bs = personProps.baseSchema
// val person1: bs.svt.Value = (20, "Vasya")
// val m1 = bs.convertToMap(person1)

@Test def schemaTest =
println(personProps.baseSchema)
val bs = personProps.baseSchema
val person1: bs.Values = (20, "Vasya")
val m1 = bs.convertToMap(person1)
// assert(bs.get(personProps.name)(person1) == Some("Vasya"))
// assert(bs.get(personProps.age)(person1) == Some(20))
// assert(bs.get(personProps.title)(person1) == None)

assert(bs.get(personProps.name)(person1) == Some("Vasya"))
assert(bs.get(personProps.age)(person1) == Some(20))
assert(bs.get(personProps.title)(person1) == None)

assert(m1 == Map("name" -> "Vasya", "age" -> 20))
// assert(m1 == Map("name" -> "Vasya", "age" -> 20))
Loading
Loading