Skip to content

Instantly share code, notes, and snippets.

@gunzip
Created October 26, 2017 09:58
Show Gist options
  • Save gunzip/8718322cc7e7ab80161d6d1a16cb8b90 to your computer and use it in GitHub Desktop.
Save gunzip/8718322cc7e7ab80161d6d1a16cb8b90 to your computer and use it in GitHub Desktop.
findLastVersionByModelId.ts
protected async findLastVersionByModelId<V>(
collectionName: string,
modelIdField: string,
modelIdValue: V
): Promise<Either<DocumentDb.QueryError, Option<TR>>> {
const errorOrMaybeDocument = await DocumentDbUtils.queryOneDocument(
this.dbClient,
this.collectionUri,
{
parameters: [
{
name: "@modelId",
value: modelIdValue
}
],
query: `SELECT * FROM ${collectionName} m WHERE (m.${modelIdField} = @modelId) ORDER BY m.version DESC`
}
);
return errorOrMaybeDocument.mapRight(maybeDocument =>
maybeDocument.map(this.toRetrieved)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment