Skip to content

Commit

Permalink
Merge pull request #5 from 365talents/type-property-column-name-funct…
Browse files Browse the repository at this point in the history
…ions

New Release 3.1.2-fork1
  • Loading branch information
ducher authored Oct 9, 2023
2 parents f187c9c + d22e0ca commit 6d7970c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
6 changes: 6 additions & 0 deletions doc/release-notes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.1.2-fork1

### What's new

- Better typings for `propertyNameToColumnName` and `columnNameToPropertyName`

## 3.1.2

### What's new
Expand Down
39 changes: 29 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "objection",
"version": "3.1.2",
"version": "3.1.2-fork1",
"description": "An SQL-friendly ORM for Node.js",
"main": "lib/objection.js",
"license": "MIT",
Expand Down Expand Up @@ -55,7 +55,8 @@
"dependencies": {
"ajv": "^8.6.2",
"ajv-formats": "^2.1.1",
"db-errors": "^0.2.3"
"db-errors": "^0.2.3",
"type-fest": "^4.4.0"
},
"peerDependencies": {
"knex": ">=1.0.1"
Expand Down
14 changes: 14 additions & 0 deletions tests/ts/model-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,17 @@ import { ModelClass } from '../../';
const persons = await modelClass.query().where('firstName', 'Jennifer');
const persons2: Person[] = await modelClass.fetchGraph(persons, 'pets');
})();

(async () => {
const property: string = Person.propertyNameToColumnName('firstName');

// @ts-expect-error
const propertyFail: string = Person.propertyNameToColumnName('first_name');
})();

(async () => {
// @ts-expect-error
const propertyFail: string = Person.columnNameToPropertyName('firstName');

const property: string = Person.columnNameToPropertyName('first_name');
})();
5 changes: 3 additions & 2 deletions typings/objection/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import Ajv, { Options as AjvOptions } from 'ajv';
import * as dbErrors from 'db-errors';
import { Knex } from 'knex';
import { SnakeCase, SnakeCasedProperties } from 'type-fest';

// Export the entire Objection namespace.
export = Objection;
Expand Down Expand Up @@ -1563,8 +1564,8 @@ declare namespace Objection {

static defaultGraphOptions?: GraphOptions;

static columnNameToPropertyName(propertyName: string): string;
static propertyNameToColumnName(propertyName: string): string;
static columnNameToPropertyName<M extends Model>(this: Constructor<M>, col: SnakeCase<ModelProps<M>>): string;
static propertyNameToColumnName<M extends Model>(this: Constructor<M>, col: ModelProps<M>): string;

static query<M extends Model>(
this: Constructor<M>,
Expand Down

0 comments on commit 6d7970c

Please sign in to comment.