loopbackjs

How to Dynamically Create and Expose a New REST Endpoint In Code (on the fly) for a Custom Loopback Model

喜你入骨 提交于 2019-12-12 01:59:06
问题 We're developing a SaaS accounting product that uses the Loopback REST framework and allows authenticated end users to create new tables in their own database instance (MySQL or PostgreSQL). QUESTION : How can we create a new root level Looback REST endpoint in code (on the fly) to access the new table? For example if the user adds a new table named 'cars' we need to expose a new root level REST endpoint in code called '/api/cars' that uses the persisted model to provide full CRUD capability

How to get auto Id after upsert on a persisted model in loopback?

你离开我真会死。 提交于 2019-12-12 00:48:50
问题 I have a some models generated from postgresql db using looback-connector postgresql. Id column of these models is a auto incremented integer column of postgresql db. 1) I have a remote method added on one of persisted models, where i perform simple update or insert(upsert. Car.CreateOrUpdateCar = function (carobj, req) { Car.upsert(Carobj, function (err, Car) { if (err) console.log(err); else { req(err, Car); } }); }; 2) have added a remote hook to execute after this remote method. Car

How to make a model in loopback 4 to have unique values in its schema?

守給你的承諾、 提交于 2019-12-11 18:26:20
问题 I am trying to find a way to have the same funtionality that happens when I put unique:true in express schema. How do I accomplish this in loopback 4. I tried putting unique true in the property decorator but it did not work. @property({ type: 'string', id: true, required: false, unique: true, }) id: string; This doesnt work 回答1: @property decorator in LB4 borrows the same properties as in LB3. Assuming that I have understood your requirements, you can make use of the index property to

Loopback get data from one module to anothee

蓝咒 提交于 2019-12-11 17:18:52
问题 I am using loopback3 for file storage attachment.js and i have the persistedmodel career.js for storing the data. Now i want to fetch the file name in the career.js. how to do this. career.js 'use strict'; const app = require('../../server/server'); module.exports = function(Career) { Career.afterRemote('create', function(context, remoteMethodOutput, next) { next(); // console.log(context.result) Career.app.models.Email.send({ to: 'john@gmail.com', from: 'noreply@gmail.com', subject: 'Career

loopback where field is null

▼魔方 西西 提交于 2019-12-11 15:56:39
问题 How can I query a field which is null? I get a a sql error filter=[where][category_id][eq][null] results in SELECT WHERE category_id'null' ORDER BY id using latest version of loopback and loopback-connector-mysql 回答1: You can use filter like /model?filter[where][category_id][eq]=null As you see in loopback /medias?filter[where][keywords][inq]=foo&filter[where][keywords][inq]=bar reference link : here 来源: https://stackoverflow.com/questions/52485321/loopback-where-field-is-null

loopback session no method create?

。_饼干妹妹 提交于 2019-12-11 15:14:14
问题 When I use login function User.login({email: 'foo@bar.com', password: 'bar'}, function(err, accessToken) { console.log(err); console.log(accessToken); }) the error is TypeError : Object [Model session] has no method 'create' 回答1: It looks like you are using an old version of LoopBack. Try upgrading and making sure the user model is attached to a data source. Below are the steps to do this. // # Verify version // Ω slc version // slc v2.1.1 (node v0.10.9) // # upgrade with `npm install strong

Create model in model

若如初见. 提交于 2019-12-11 12:14:23
问题 I'm new to strongloop and look at documentation and samples but never see my problem as desired. I'v two models, sentence.js and log.js and making post request a sentence from mobile app to rest-api, for example Model sentence.js (dont want save to db this model, only for parsing and creating log model) { name: 'sentence', type: 'string' } Model log.js { name: 'lat', type: 'string' }, { name: 'lng', type: 'string' } [HTTP POST] myserver/api/sentence?d=$GPRMC,123519,A,4807.038,N,01131.000,E

Getting joined data from strongloop/loopback

江枫思渺然 提交于 2019-12-11 11:31:38
问题 How can I get data from two joined tables? Suppose, there are two models called Category (CategoryId, CategoryName) and Product(ProductId, ProductName, CategoryId), Is there a way to get a result like:(ProductId, ProductName, CategoryId, CategoryName) 回答1: There should be a relation between your Category model and your Product model. A Category hasMany Products and each Product belongsTo a Category. So your model json files should be something like Category: { "name":"Category", "properties":

Can't kill NodeJS app

别说谁变了你拦得住时间么 提交于 2019-12-11 10:50:59
问题 One day, out of nothing, my app decided not to die. After pressing ctrl + c when I inspect port it's still there and not only on my machine but also on server that is managed by PM2 so I need to go there each time and kill the process by hand. I tried to look for issues in my code and when I couldn't I just though that it's simply one of the dependencies fault and soon there will be a fix. It was slightly annoying but I could kill the process with kill -9 PID and I had most of the tasks I had

is it possible to use StrongLoop Arc to create a relationship between two models?

戏子无情 提交于 2019-12-11 10:28:28
问题 In this loopback tutorial we can see how own can create model relationships http://docs.strongloop.com/display/public/LB/Tutorial%3A+model+relations#Tutorial:modelrelations-Createmodelrelations Is the same possible in StrongLoop Arc? Thanks 回答1: Loopback and Arc have sort of different functions. For instance the Loopback framework is a set of Node.js modules that you can use independently or together. While Arc is a visual tool suite for creating, packaging, deploying, profiling, managing,