Skip to content

Commit

Permalink
feat: expose default naming strategy from Orm binding (#689)
Browse files Browse the repository at this point in the history
* feat: expose default naming strategy from Orm binding

Closes: #688

* fix
  • Loading branch information
targos authored Jun 2, 2021
1 parent 2d0ac5e commit b693054
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions adonis-typings/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module '@ioc:Adonis/Lucid/Orm' {
DateColumnDecorator,
ModelPaginatorContract,
DateTimeColumnDecorator,
NamingStrategyContract,
} from '@ioc:Adonis/Lucid/Model'

import { SimplePaginatorMetaKeys } from '@ioc:Adonis/Lucid/Database'
Expand Down Expand Up @@ -45,6 +46,9 @@ declare module '@ioc:Adonis/Lucid/Orm' {
ModelPaginatorContract,
} from '@ioc:Adonis/Lucid/Model'

export const SnakeCaseNamingStrategy: {
new (): NamingStrategyContract
}
export const scope: ScopeFn
export const BaseModel: LucidModel

Expand Down
2 changes: 2 additions & 0 deletions providers/DatabaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class DatabaseServiceProvider {
const decorators = require('../src/Orm/Decorators')
const { BaseModel } = require('../src/Orm/BaseModel')
const { ModelPaginator } = require('../src/Orm/Paginator')
const { SnakeCaseNamingStrategy } = require('../src/Orm/NamingStrategies/SnakeCase')

/**
* Attaching adapter to the base model. Each model is allowed to define
Expand All @@ -52,6 +53,7 @@ export default class DatabaseServiceProvider {
return {
BaseModel,
ModelPaginator,
SnakeCaseNamingStrategy,
scope,
...decorators,
}
Expand Down
2 changes: 2 additions & 0 deletions test/database-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FactoryManager } from '../src/Factory'
import { BaseModel } from '../src/Orm/BaseModel'
import { ModelPaginator } from '../src/Orm/Paginator'
import * as decorators from '../src/Orm/Decorators'
import { SnakeCaseNamingStrategy } from '../src/Orm/NamingStrategies/SnakeCase'

import { setupApplication, fs } from '../test-helpers'

Expand All @@ -39,6 +40,7 @@ test.group('Database Provider', (group) => {
assert.deepEqual(app.container.use('Adonis/Lucid/Orm'), {
BaseModel,
ModelPaginator,
SnakeCaseNamingStrategy,
scope,
...decorators,
})
Expand Down

0 comments on commit b693054

Please sign in to comment.