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

fix: fix scope type definitions #402

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spell.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Spell<T extends typeof AbstractBone, U = InstanceType<T> | Collecti
connection: Connection;

command: string;
scopes: Array<(spell: this) => void>;
scopes: Array<ScopeFunction>;

select(...names: Array<string | Raw> | Array<(name: string) => boolean>): Spell<T, U>;
insert(opts: SetOptions<T>): Spell<T, QueryResult>;
Expand Down
29 changes: 22 additions & 7 deletions test/types/spell.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { strict as assert } from 'assert';
import sinon from 'sinon';

import {
import {
Bone, DataTypes, Column,
connect, INDEX_HINT_SCOPE_TYPE,
INDEX_HINT_TYPE, INDEX_HINT_SCOPE, Hint, IndexHint, Raw
INDEX_HINT_TYPE, INDEX_HINT_SCOPE, Hint, IndexHint, Raw, heresql,
} from '../..';
import { HasOne } from '../../src/decorators';

Expand Down Expand Up @@ -198,7 +198,7 @@ describe('=> Spell (TypeScript)', function() {

it('mixing', () => {
assert.equal(
Post.update({ id: 1 }, { title: 'ssss' }, {
Post.update({ id: 1 }, { title: 'ssss' }, {
silent: true,
hints: [
'idx_title',
Expand All @@ -221,11 +221,11 @@ describe('=> Spell (TypeScript)', function() {
const fakeDate = date.getTime();
sinon.useFakeTimers(fakeDate);
});

after(() => {
clock?.restore();
});

it('count', () => {
assert.equal(Post.all.count('authorId').toSqlString(), 'SELECT COUNT(`author_id`) AS `count` FROM `articles` WHERE `gmt_deleted` IS NULL');
assert.equal(Post.all.count(new Raw(`DISTINCT(author_id)`)).toSqlString(), 'SELECT COUNT(DISTINCT(author_id)) AS count FROM `articles` WHERE `gmt_deleted` IS NULL');
Expand Down Expand Up @@ -289,12 +289,27 @@ describe('=> Spell (TypeScript)', function() {
'SELECT `posts`.`title`, `posts`.`gmt_create`, `attachment`.* FROM `articles` AS `posts` LEFT JOIN `attachments` AS `attachment` ON `posts`.`id` = `attachment`.`article_id` AND `attachment`.`gmt_deleted` IS NULL WHERE `posts`.`gmt_deleted` IS NULL'
);
});

it('arbitrary join', function() {
assert.equal(
Post.join(Comment, 'comments.articleId = posts.id').toString(),
'SELECT `posts`.*, `comments`.* FROM `articles` AS `posts` LEFT JOIN `comments` AS `comments` ON `comments`.`article_id` = `posts`.`id` WHERE `posts`.`gmt_deleted` IS NULL'
);
});
})
});

describe('from', () => {
it('should work', function () {
assert.equal(Post.from(Post.where({
title: {
$like: '%yoxi%',
}
})).limit(1).toSqlString(), heresql(function () {
/*
SELECT *
FROM (SELECT * FROM `articles` WHERE `title` LIKE '%yoxi%' AND `gmt_deleted` IS NULL) AS `posts`
LIMIT 1
*/}));
});
});
});
Loading