Created
October 26, 2017 09:58
-
-
Save gunzip/8718322cc7e7ab80161d6d1a16cb8b90 to your computer and use it in GitHub Desktop.
findLastVersionByModelId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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