stefnotch / sepm-project

TU Vienna - Group Project Frontend
https://stefnotch.github.io/sepm-project/
MIT License
0 stars 1 forks source link

Source code generator #1

Open stefnotch opened 1 year ago

stefnotch commented 1 year ago

Goals

https://github.com/forge/roaster

stefnotch commented 1 year ago

https://thorben-janssen.com/result-set-mapping-basics/ https://thorben-janssen.com/result-set-mapping-constructor-result-mappings/

It'd be cool if you can just do the database calls directly from the frontend and have all the backend Java stuff generated for you.

The tough part is that it needs to be user-extensible. Aka the user should still be able to write their own backend code and it should be neatly integrated into the autogenerated code.

stefnotch commented 1 year ago
let artist = Entity("artist")
.id()
.column(name, StringType)
.colum(fanOf, () => OptionalType(artist))

let db=Database({artist: artist, cat: cat, ..})

let query = db.select("artist").where(builder => "ID = 6 haha hardcoding a where").pagination()

let query2 = db.withInputs({id: NumberType}).select("artist").where(b => b.equals(b.table.artist.id, b.input.id))

let artistAndCountry = Entity(..)
column name string
column country string

let query3 = db.select(artistAndCountry).from(artist)...

let artistLayers = Layers({ entity: artist, queries: { getSix: query, byId: query2 } })
artistLayers.service.byId.custom()

let generated = Generator({ database })
.addLayers(artistLayers)

generated.write()
// Create table
// Entity class
// Endpoint with get for selects
// Dto for selects
// Service that forwards the calls, custom means it writes the code and wraps it in a comment that includes a stable ID...
// JPA query

Missing:
- auth
- validation, can be replaced with .custom() or .extensionPoint() 
- transactions https://stackoverflow.com/questions/26200324/how-to-rollback-transaction-in-jpa
- @Lock(LockModeType.PESSIMISTIC_WRITE)
- complex queries, like a search query with optional filters, recursive queries, can be replaced with .custom() or .extensionPoint() 
- imports, can be replaced with .custom() or .extensionPoint()
- https://github.com/Blazebit/blaze-persistence#core-quick-start
stefnotch commented 1 year ago

https://codebase.show/projects/realworld?category=backend&language=java has example projects

stefnotch commented 1 year ago

Entity Graph https://www.youtube.com/watch?v=_6Ni_wxfoyI