foldables-io / skunk-tables Goto Github PK
View Code? Open in Web Editor NEWType-safe high-level ORM for Postgres
License: Apache License 2.0
Type-safe high-level ORM for Postgres
License: Apache License 2.0
This is a regression since first RCs. If I use an opaque types as on of the members I get type mismatch errors:
[error] 68 | Tuple1(columns.created_by.from(_.createdBy))
[error] | ^^^^^^^^^^^
[error] |Found: (_$1.createdBy : io.foldables.ratio.services.auth.model.Actor.Id)
[error] |Required: java.util.UUID
Couldn't investigate it deeper, but there's some connection between where the type is defined (same file/object) and error message.
Anyway, getting rid of TypeRepr.of[Columns]
in TableBuilder
seems to be solving the problem.
Just a weird name.
We can declare some members of a table class as "foreign keys", i.e. instead of an actual column in a table they're references to another relation-table. For example:
A persons
table:
id first_name last_name
1 John Smith
A Person
class:
case class Person(firstName: String, lastName: String, photos: List[Photo.Id])
Here, photos
is a reference to persons_photos
relation table:
person_id photo_id
1 1
1 2
1 3
So expressing this relation would look like:
Table
.of[Person]
.withName("persons")
.withPrimary("id")
.withForeign[Photo.Id]("photos", "id")
.build
This way, whenever we do Person.table.get(personId)
- it also queries all photos.
Following should work:
case class Task(id: String)
object Task:
val table = Table.of[Task].withName("tasks").build
Currently, when we transform query (e.g. by adding limit
) we in fact just concatenate Fragments
which is very unsafe. Instead I think we should create a SELECT
AST (later for INSERT
and UDPATE
as well) and when transforming method is called - we can just patch the bits of this AST. The AST could live in compile-time only, thus it doesn't even have to be completely type-safe.
Select(All, From("persons"), Where(Gte("age", 18)))
Currently it provides only columns with unique constraints. But:
columns.id > 10
which doesn't return single element - we must make sure there's always ==
operator used on a unique columnCurrently we support only snake_case convention.
This is something I've started (https://github.com/foldables-io/skunk-tables/blob/main/core/src/main/scala/skunk/tables/NameStrategy.scala), but never finished.
Probably should be working only with numeric types.
Currently it has only universal equality:
skunk-tables/core/src/main/scala/skunk/tables/TypedColumn.scala
Lines 46 to 47 in a9754af
At least:
>
<
>=
<=
In the below code:
opaque type Id = Long
inline given IsColumn[Id] = ???
case class Task(id: Id, title: Task.Title)
object Task:
opaque type Title = String
inline given IsColumn[Title] = ???
val table = Table.of[Task].withName("tasks").build
Columns in table
end up being:
(TypedColumn["id", Long, "tasks", EmptyTuple], TypedColumn["title", Task.Title, "tasks", EmptyTuple])
And the only difference between Id
and Title
is that they're defined at different levels. I managed to narrow down this problem to quotidian.MacroMirror
, i.e. at this moment at the very beginning of MacroTable
existence I already have wrong types.
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.