Skip to content

eimsound/ktor-jimmer-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ktor Jimmer Rest

A Ktor plugin that provides a concise DSL-style API for building RESTful web services based on Ktor and Jimmer

license jimmer

Start

Add ktor-jimmer-rest to your project

implementation("com.eimsound:ktor-jimmer-rest")

Use the JimmerRest plugin in your project

install(JimmerRest) {
    jimmerSqlClientFactory {
        inject<KSqlClient>()
    }
}

Usage

Provides five types of routes (create | remove | edit | id | list). For detailed usage, refer to the documentation. Here, the list is used as an example.

list<Book> {
    filter {
        where(
            `ilike?`(table::name),
            `ilike?`(table.store::name),
            `between?`(table::price)
        )
        orderBy(table.id.desc())
    }
    fetcher {
        by {
            allScalarFields()
            name()
            store {
                name()
                website()
            }
            authors {
                name()
                firstName()
                lastName()
            }
        }
    }
}
  • Inside list<T>{}, T is a jimmer entity class, used to mark the context type
  • The filter conditions inside filter are the functions provided by jimmer, and we have added extensions to these functions, for example, `between?`(table::price) is nullable and will be mapped to the price__ge | price__le query parameter, and for __ge | __le, it is a special extension of `between?`, `ilike?` can be used with the suffixes __anywhere | __exact | __start | __end, which correspond to different filtering functions, see the documentation for details
  • fetcher then continues to use the functionality of jimmer, jimmer is indeed a very powerful orm framework, and writing it is very elegant, please refer to jimmer's documentation for details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages