Skip to content

Commit

Permalink
fix: select((name: string) => boolean) (#227)
Browse files Browse the repository at this point in the history
fixes #223
  • Loading branch information
cyjake authored Nov 12, 2021
1 parent 4ba60e7 commit 2b03940
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
7 changes: 0 additions & 7 deletions test/types/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ describe('=> Basics (TypeScript)', function() {
});
});

describe('=> Collection', function() {
it('collection.toJSON()', async function() {
const posts = await Post.all;
assert.deepEqual(posts.toJSON(), []);
});
});

describe('=> Create', function() {
it('Bone.create()', async function() {
const post = await Post.create({ title: 'Tyrael' });
Expand Down
9 changes: 9 additions & 0 deletions test/types/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ describe('=> Collection (TypeScript)', function() {
});
});

beforeEach(async function() {
await User.truncate();
});

it('collection.toJSON()', async function() {
const uesrs = await User.all;
assert.deepEqual(uesrs.toJSON(), []);
});

it('collection.save()', async function() {
const users = new Collection(
new User({ nickname: 'siri', email: '[email protected]', status: 0 }),
Expand Down
11 changes: 11 additions & 0 deletions test/types/querying.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Bone, connect } from '../..'
describe('=> Querying (TypeScript)', function() {
class Post extends Bone {
static table = 'articles'
id: bigint;
title: string;
}

Expand Down Expand Up @@ -79,4 +80,14 @@ describe('=> Querying (TypeScript)', function() {
assert.equal(count, 0);
});
});

describe('=> Select', async function() {
before(async function() {
await Post.bulkCreate([
{ title: 'There And Back Again' },
]);
})
const post = await Post.findOne().select(name => [ 'id', 'title' ].includes(name));
assert.deepEqual(post.toJSON(), { id: post.id, title: 'There And Back Again' })
});
});
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type WithOptions = {
export class Spell<T extends typeof Bone, U = InstanceType<T> | Collection<InstanceType<T>> | ResultSet | number | null> extends Promise<U> {
constructor(Model: T, opts: SpellOptions);

select(...names: Array<string | RawSql>): Spell<T, U>;
select(...names: Array<string | RawSql> | Array<(name: string) => boolean>): Spell<T, U>;
insert(opts: SetOptions): Spell<T, number>;
update(opts: SetOptions): Spell<T, number>;
upsert(opts: SetOptions): Spell<T, number>;
Expand Down

0 comments on commit 2b03940

Please sign in to comment.