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

Source code generator #1

Open
stefnotch opened this issue Dec 15, 2022 · 4 comments
Open

Source code generator #1

stefnotch opened this issue Dec 15, 2022 · 4 comments

Comments

@stefnotch
Copy link
Owner

stefnotch commented Dec 15, 2022

Goals

  • Generates source code that you would have written
    • Properly formatted
    • Decent names
    • Well architected
    • aka readable, and doesn't look like minified, absolutely compiler generated code
  • Extensible in the target language
    • Lets you tweak the generated code and work with it
    • You don't have to know the inner workings of the generator. Instead you really do get to directly edit the generated code.
  • Can be re-executed repeatedly
    • Cleans up useless files
      • If a generated file no longer gets generated, then the generator detects that, tells you about it, and removes that file
    • Updates generated source code (overwrite)
    • Detects user modifications and warns (compares hash with hash stored in a comment, for figuring out the exact changes, you should ask your VCS)
    • Keeps specially marked user modifications in place

https://github.com/forge/roaster

@stefnotch
Copy link
Owner Author

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
Copy link
Owner Author

stefnotch commented Feb 16, 2023

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
Copy link
Owner Author

@stefnotch
Copy link
Owner Author

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

@stefnotch stefnotch changed the title Code Gen Source code generator Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant