Skip to content

Commit

Permalink
Merge branch 'adonisjs:21.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zaosoula authored Nov 15, 2024
2 parents 643cd1d + d5354ae commit a0417b9
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 94 deletions.
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: test
on:
- push
- pull_request
- workflow_call

jobs:
lint:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Sync labels
on:
workflow_dispatch:
permissions:
issues: write
jobs:
labels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EndBug/label-sync@v2
with:
config-file: 'https://raw.githubusercontent.com/thetutlage/static/main/labels.yml'
delete-other-labels: true
token: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: release
on: workflow_dispatch
permissions:
contents: write
id-token: write
jobs:
checks:
uses: ./.github/workflows/checks.yml
release:
needs: checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- name: git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Init npm config
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm install
- run: npm run release -- --ci
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 10 additions & 0 deletions commands/migration/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default class Refresh extends BaseCommand {
@flags.boolean({ description: 'Run seeders' })
declare seed: boolean

/**
* Display migrations result in one compact single-line output
*/
@flags.boolean({ description: 'A compact single-line output' })
declare compactOutput: boolean

/**
* Disable advisory locks
*/
Expand All @@ -60,6 +66,10 @@ export default class Refresh extends BaseCommand {
args.push('--force')
}

if (this.compactOutput) {
args.push('--compact-output')
}

if (this.connection) {
args.push(`--connection=${this.connection}`)
}
Expand Down
10 changes: 10 additions & 0 deletions commands/migration/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export default class Reset extends BaseCommand {
@flags.boolean({ description: 'Do not run actual queries. Instead view the SQL output' })
declare dryRun: boolean

/**
* Display migrations result in one compact single-line output
*/
@flags.boolean({ description: 'A compact single-line output' })
declare compactOutput: boolean

/**
* Disable advisory locks
*/
Expand All @@ -54,6 +60,10 @@ export default class Reset extends BaseCommand {
args.push('--force')
}

if (this.compactOutput) {
args.push('--compact-output')
}

if (this.connection) {
args.push(`--connection=${this.connection}`)
}
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { configPkg } from '@adonisjs/eslint-config'
export default configPkg()
97 changes: 56 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@adonisjs/lucid",
"description": "SQL ORM built on top of Active Record pattern",
"version": "21.1.0",
"version": "21.4.0",
"engines": {
"node": ">=18.16.0"
},
Expand All @@ -25,6 +25,7 @@
"./factories": "./build/src/factories/main.js",
"./database": "./build/src/database/main.js",
"./orm": "./build/src/orm/main.js",
"./orm/relations": "./build/src/orm/relations/main.js",
"./seeders": "./build/src/seeders/main.js",
"./services/*": "./build/services/*.js",
"./types/*": "./build/src/types/*.js",
Expand All @@ -43,75 +44,71 @@
"test:pg": "cross-env DB=pg node --enable-source-maps --loader=ts-node/esm ./bin/test.js",
"test:docker": "npm run test:mysql && npm run test:mysql_legacy && npm run test:pg && npm run test:mssql",
"quick:test": "cross-env DB=sqlite node --enable-source-maps --loader=ts-node/esm ./bin/test.js",
"lint": "eslint . --ext=.ts",
"lint": "eslint",
"clean": "del-cli build",
"compile": "npm run lint && npm run clean && tsc",
"postcompile": "npm run copy:templates && npm run index:commands",
"copy:templates": "copyfiles \"stubs/**/**/*.stub\" build",
"build": "npm run compile",
"release": "np",
"release": "release-it",
"version": "npm run build",
"typecheck": "tsc --noEmit",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/lucid",
"format": "prettier --write .",
"prepublishOnly": "npm run build",
"test": "c8 npm run test:docker",
"index:commands": "adonis-kit index build/commands"
},
"devDependencies": {
"@adonisjs/assembler": "^7.7.0",
"@adonisjs/core": "^6.11.0",
"@adonisjs/eslint-config": "^1.3.0",
"@adonisjs/prettier-config": "^1.3.0",
"@adonisjs/tsconfig": "^1.3.0",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@adonisjs/assembler": "^7.8.2",
"@adonisjs/core": "^6.14.1",
"@adonisjs/eslint-config": "^2.0.0-beta.7",
"@adonisjs/prettier-config": "^1.4.0",
"@adonisjs/tsconfig": "^1.4.0",
"@japa/assert": "^3.0.0",
"@japa/file-system": "^2.3.0",
"@japa/runner": "^3.1.4",
"@libsql/sqlite3": "^0.3.1",
"@swc/core": "^1.6.1",
"@release-it/conventional-changelog": "^9.0.3",
"@swc/core": "^1.9.2",
"@types/chance": "^1.1.6",
"@types/luxon": "^3.4.2",
"@types/node": "^20.14.5",
"@types/node": "^22.9.0",
"@types/pretty-hrtime": "^1.0.3",
"@types/qs": "^6.9.15",
"@types/qs": "^6.9.17",
"@vinejs/vine": "^2.1.0",
"better-sqlite3": "^11.0.0",
"better-sqlite3": "^11.5.0",
"c8": "^10.1.2",
"chance": "^1.1.11",
"chance": "^1.1.12",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"del-cli": "^5.1.0",
"del-cli": "^6.0.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint": "^9.14.0",
"fs-extra": "^11.2.0",
"github-label-sync": "^2.3.1",
"husky": "^9.0.11",
"luxon": "^3.4.4",
"mysql2": "^3.10.1",
"np": "^10.0.6",
"pg": "^8.12.0",
"prettier": "^3.3.2",
"luxon": "^3.5.0",
"mysql2": "^3.11.4",
"pg": "^8.13.1",
"prettier": "^3.3.3",
"reflect-metadata": "^0.2.2",
"release-it": "^17.10.0",
"sqlite3": "^5.1.7",
"tedious": "^18.2.0",
"tedious": "^18.6.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
"typescript": "^5.6.3"
},
"dependencies": {
"@adonisjs/presets": "^2.6.1",
"@faker-js/faker": "^8.4.1",
"@poppinss/hooks": "^7.2.3",
"@poppinss/macroable": "^1.0.2",
"@poppinss/utils": "^6.7.3",
"@adonisjs/presets": "^2.6.3",
"@faker-js/faker": "^9.2.0",
"@poppinss/hooks": "^7.2.4",
"@poppinss/macroable": "^1.0.3",
"@poppinss/utils": "^6.8.3",
"fast-deep-equal": "^3.1.3",
"igniculus": "^1.5.0",
"kleur": "^4.1.5",
"knex": "^3.1.0",
"knex-dynamic-connection": "^3.2.0",
"pretty-hrtime": "^1.0.3",
"qs": "^6.12.1",
"qs": "^6.13.0",
"slash": "^5.1.0",
"tarn": "^3.0.2"
},
Expand All @@ -138,8 +135,8 @@
"bugs": {
"url": "https://github.com/adonisjs/lucid/issues"
},
"eslintConfig": {
"extends": "@adonisjs/eslint-config/package"
"overrides": {
"strtok3": "8.0.1"
},
"prettier": "@adonisjs/prettier-config",
"commitlint": {
Expand All @@ -149,13 +146,31 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"provenance": true
},
"np": {
"message": "chore(release): %s",
"tag": "latest",
"branch": "main",
"anyBranch": false
"release-it": {
"git": {
"requireCleanWorkingDir": true,
"requireUpstream": true,
"commitMessage": "chore(release): ${version}",
"tagAnnotation": "v${version}",
"push": true,
"tagName": "v${version}"
},
"github": {
"release": true
},
"npm": {
"publish": true,
"skipChecks": true
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": {
"name": "angular"
}
}
}
},
"c8": {
"reporter": [
Expand Down
20 changes: 15 additions & 5 deletions src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,23 @@ export class Connection extends EventEmitter implements ConnectionContract {
}

/**
* Cleanup references
* Cleans up reference for the write client and also the
* read client when not using replicas
*/
private cleanup(): void {
private cleanupWriteClient() {
if (this.client === this.readClient) {
this.cleanupReadClient()
}
this.client = undefined
}

/**
* Cleans up reference for the read client
*/
private cleanupReadClient() {
this.roundRobinCounter = 0
this.readClient = undefined
this.readReplicas = []
this.roundRobinCounter = 0
}

/**
Expand All @@ -127,15 +137,15 @@ export class Connection extends EventEmitter implements ConnectionContract {
*/
this.pool!.on('poolDestroySuccess', () => {
this.logger.trace({ connection: this.name }, 'pool destroyed, cleaning up resource')
this.cleanup()
this.cleanupWriteClient()
this.emit('disconnect', this)
this.removeAllListeners()
})

if (this.readPool !== this.pool) {
this.readPool!.on('poolDestroySuccess', () => {
this.logger.trace({ connection: this.name }, 'pool destroyed, cleaning up resource')
this.cleanup()
this.cleanupReadClient()
this.emit('disconnect', this)
this.removeAllListeners()
})
Expand Down
11 changes: 9 additions & 2 deletions src/database/query_builder/chainable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ export abstract class Chainable extends Macroable implements ChainableContract {
*/
protected transformValue(value: any) {
if (value instanceof Chainable) {
value.applyWhere()
return value.knexQuery
return value.toKnex()
}

if (value instanceof ReferenceBuilder) {
Expand Down Expand Up @@ -2074,4 +2073,12 @@ export abstract class Chainable extends Macroable implements ChainableContract {

return this
}

/**
* Applies statements and returns knex query
*/
toKnex() {
this.applyWhere()
return this.knexQuery
}
}
10 changes: 10 additions & 0 deletions src/orm/base_model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,16 @@ class BaseModelImpl implements LucidRow {
.processAllForOne(this, queryClient)
}

/**
* Load relationships onto the instance, but only if they are not
* already preloaded
*/
async loadOnce(relationName: any) {
if (!this.$preloaded[relationName]) {
return this.load(relationName)
}
}

/**
* @deprecated
*/
Expand Down
4 changes: 3 additions & 1 deletion src/orm/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @adonisjs/lucid
*
* (c) AdoniJS
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,6 +12,8 @@ export * from './decorators/date.js'
export * from './decorators/date_time.js'
export { BaseModel, scope } from './base_model/index.js'
export { ModelQueryBuilder } from './query_builder/index.js'
export { ModelPaginator } from './paginator/index.js'
export { SnakeCaseNamingStrategy } from './naming_strategies/snake_case.js'
export { CamelCaseNamingStrategy } from './naming_strategies/camel_case.js'
export { Preloader } from './preloader/index.js'
export { Adapter } from './adapter/index.js'
Loading

0 comments on commit a0417b9

Please sign in to comment.