Using the ORM2 module in Node.js, after creating a connection and checking that works, I can't find a way to retrieve all the records of a model, like the ActiveRecord's way Model.all . I'm new to ORM2 and it seems pretty obvious, but I don't have a clue...
I think this does it:
var Blah = db.models.blah;
Blah.all(function(err, blahs){
})
Looking at the code Model.js which defines the methods for the Model (Blah above) has the following line:
model.all = model.find;
So I assume Blah.find() would work as well. The methods used in the model instances are defined in the file Instance.js. The documentation isn't super, but I have been happy with the project so far, and likely can help out if you have questions
Related
I'm trying to connect my NestJs Project with a Oracle db and I'm using TypeORM and the status of connection is ok but I don't know how I can connect with a function. This function is into of a package and at the same time this package is into of a schema. The structure is like:
mySchema:
--------->myPackage:
-------------------->myFunction(id)
In the NestJS code I'm define this import in the AppModule file:
When I try to use the entity I don't know what method can I use to connect with my function. With the ESLint I get the next methods:
I hope to be clear and thanks for all!
In you last picture you’re trying to make a request to the database and as you can see, when you mentioned the testRepository and dots(.) now you have to tell him what you want to do in your database and in the suggested list you have all the possible possibilities.
So if you want to get or fetch data from you database, you will use testRepository.find() this will give you everything in that particular entity. To do that, you have to do something like below, before that you code has something that I have never seen in Nest, (public); if it does exist but I won’t use that in my Example since I don’t know it in Nest and also; you have started writing without (return) I don’t know how you’re expecting to return what you will get from your database.
Here is my example:
in your controller:
#Get() AnyThing(): Promise<TestEntity[]> {return this.DaobscsService.whatEver(); }
And in your service:
#InjectRepository(TestEntity) private readonlytestRepository: Repository<TestEntity>, ) {}
async whatEver(): Promise<TestEntity[]> {return await this.testRepository.find();}
What ever name you gonna use instead (whatEver()) in the service that have used, remember to use the same name in your controller pointing to service (this.Boa...Service.(The name here) OOP system’s you know it I hope
This example is to get or fetch so if you don’t have any thing in your database then you will get nothing! if that’s not what u want then command with a full version of what exactly is your issue, what u expected and code from controller, service, and module.
I recently realized that DocumentDB supports stand alone update operations via ReplaceDocumentAsync.
I've replaced the Upsert operation below with the Replace operation.
var result = _client
.UpsertDocumentAsync(_collectionUri, docObject)
.Result;
So this is now:
var result = _client
.ReplaceDocumentAsnyc(_collectionUri, docObject)
.Result;
However, now I get the exception:
Microsoft.Azure.Documents.BadRequestException : ResourceType Document is unexpected.
ActivityId: b1b2fd71-3029-4d0d-bd5d-87d8d0a2fc95
No idea why, upsert and replace are of the same vein and the object is the same that worked for upsert, so I would expect it to work without problems.
All help appreciated.
Thanks
Update: Have tried to implement this using the SelfLink approach, and it works for Replace, but selflink does not work with Upsert. The behavior is quite confusing. I don't like that I have to build a self link in code using string concatenation.
I'm afraid that building the selflink with string concatenation is your only option here because ReplaceDocument(...) requires a link to the document. You show a link to the collection in your example. It won't suck the id out and find the document as you might wish.
The NPM module, documentdb-utils, has library functions for building these links but it's just using string concatenation. I have seen an equivalent library for .NET but I can't remember where. Maybe it was in an Azure example or even in the SDK now.
You can build a document link for a replace using the UriFactory helper class:
var result = _client
.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, docObject.Id), docObject)
.Result;
Unfortunately it's not very intuitive, as Larry has already pointed out, but a replace expects a document to already be there, while an upsert is what it says on the tin. Two different use-cases, I would say.
In order to update a document, you need to provide the Collection Uri. If you provide the Document Uri it returns the following:
ResourceType Document is unexpected.
Maybe the _collectionUri is a Document Uri, the assignment should look like this:
_collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName);
Maybe the question does not apply to dynamoDB due to it not being Relational Db.
However, I'm looking for a good object mapper which can be used in nodejs and aws sdk to map existing model classes to dynamoDB tables. Does anyone have experience with this issue/question, or have you used such a module/library?
If you are looking for schema:
https://github.com/clarkie/dynogels (well supported forked from vogels which has been abandoned)
https://github.com/automategreen/dynamoose (inspired by Mongoose)
If you are looking for something to throw javascript objects (even circular graphs) to:
https://github.com/aaaristo/dyngodb (alpha)
https://github.com/aaaristo/angular-gson-express-dyngodb
dyngodb has experimental support for full-text search, and transactions too.
Both are based on aws-sdk.
Also worth considering is simple marshallers, which just translate between the dynamoDB format and regular js objects or JSON.
DynamoDb-Data-Types
https://github.com/kayomarz/dynamodb-data-types
https://www.npmjs.com/package/dynamodb-data-types
"This utility helps represent AWS DynamoDb data types. It maps (marshalls) JavaScript data into the format required by DynamoDb."
dynamoDb-marshaler
https://github.com/CascadeEnergy/dynamoDb-marshaler
https://www.npmjs.com/package/dynamodb-marshaler
"Translates sane javascript objects (and JSON) into DynamoDb format and vice versa." [does not support B type.]
Update 2016-06:
Just discovered that the AWS SDK now does this for you. Their documentation is only partially converted so I guess this is a recent addition. Read about it here.
But these marshallers are still useful because there are circumstances where you can't use the new document client, eg. when processing a dynamoDB stream.
You could also try: https://dynamoosejs.com/. It is inspired by mongoose again.
If you are using Typescript, dynamo-easy might be a good option. Just add some decorators to your model and start using it.
import { Model, PartitionKey, DynamoStore } from '#shiftcoders/dynamo-easy'
#Model()
export class Person {
#PartitionKey()
id: string
name: string
yearOfBirth: number
}
const personStore = new DynamoStore(Person)
personStore
.scan()
.whereAttribute('yearOfBirth').equals(1958)
.exec()
.then(res => console.log('ALL items with yearOfBirth == 1958', res))
It uses the AWS DynamoDB sdk but takes care of the mapping between JS and DynamoDB types and provides a simple to use fluent API.
full disclosure: I am one of the authors of this library
After looking over all the posts I landed on https://github.com/awspilot/dynamodb-oop
It doesn't hide the API but instead just wraps it in a nice, fluent way with promises even and you inject your version of the aws-sdk. It's similar to dynamodb-data-types but also wraps the methods too (not just the data types).
Extra bonus, the same author has https://github.com/awspilot/dynamodb-sql Didn't use the sql wrapper but I can see how some people may prefer that.
Dynamoose is obviously inspired by mongoose and is a good choice if you have a well-defined schema and/or want to be abstracted away from the DynamoDB details.
Have you seen dynasaur? It seems to be the type of thing you're looking for, but I have not used it myself. There's also dynamodb-data-types which is not an ORM, but makes it easy to convert to/from standard JavaScript objects.
i'm new to neo4j, i'm reading the documentation and a sample, small app based on the node module (neo4j), but i don't see a way to get a node or nodes based on parameter/r.
something like:
var node = db.find({user: "WillSmith#iam.com", password: "5#^632g23^##23"});
Can anyone explane it to me, or point me to a good resource explaining it :)
As far as i know, if you want to find nodes by property, you should search in index.
This index you should create by yourself.
In this file i can see functions for working with indexes, unfortunately i've implemented this only in java, so i cant help with exact implementation. Hope, it helps =)
I'm new with node and compound. While i tried to scaffold
compound g crud leaveApplication leave_code:string description:string applicable:string carry_forward:boolean limit_type:boolean lop:boolean od:boolean co:boolean leave_revision:boolean active:boolean
I was getting some errors, then i tried
compound g crud leave code:string description:string applicable:string cForward:boolean limit:boolean lop:boolean od:boolean co:boolean leave_revision:boolean active:boolean
But the error now occurred was in the name of routes
leaves GET /leaves.:format? leaves#index
leaves POST /leaves.:format? leaves#create
new_leafe GET /leaves/new.:format? leaves#new
edit_leafe GET /leaves/:id/edit.:format? leaves#edit
leafe DELETE /leaves/:id.:format? leaves#destroy
leafe PUT /leaves/:id.:format? leaves#update
leafe GET /leaves/:id.:format? leaves#show
These were the routes i was getting.
Why is that so?
it looks like compound is turning your model name into plural (=leaves) and then, instead of using your provided singular name, turning this plural name back, resulting in "leaf".
Does this make any sense? ;-) Or did I get you question wrong?
If you could provide the "some errors" and the full error message, it would be easier to help ;)
Btw, I just experienced that using camel case for models doesn't seem to be a good idea with compound.js.
It's mangeling the camelcase in some places (e.g. inside the controllers), but in others not (schema.js) creating a application with some errors...