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

feat(repository): add execute implementation #2681

Merged
merged 2 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,25 @@ describe('DefaultCrudRepository', () => {
const ok = await repo.exists(note1.id);
expect(ok).to.be.true();
});

it('implements Repository.execute()', async () => {
// Dummy implementation for execute() in datasource
ds.execute = (command, parameters, options) => {
return Promise.resolve({command, parameters, options});
};
const repo = new DefaultCrudRepository(Note, ds);
const result = await repo.execute('query', ['arg']);
expect(result).to.eql({
command: 'query',
parameters: ['arg'],
options: undefined,
});
});

it(`throws error when execute() not implemented by ds connector`, async () => {
const repo = new DefaultCrudRepository(Note, ds);
await expect(repo.execute('query', [])).to.be.rejectedWith(
'execute() must be implemented by the connector',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,10 @@ export class DefaultCrudRepository<T extends Entity, ID>

async execute(
command: Command,
// tslint:disable:no-any
parameters: NamedParameters | PositionalParameters,
options?: Options,
): Promise<AnyObject> {
/* istanbul ignore next */
throw new Error('Not implemented');
return ensurePromise(this.dataSource.execute(command, parameters, options));
}

protected toEntity(model: juggler.PersistedModel): T {
Expand Down