Skip to content

Instantly share code, notes, and snippets.

@silverbux
Last active August 29, 2015 14:28
Show Gist options
  • Save silverbux/28694a64941290644a22 to your computer and use it in GitHub Desktop.
Save silverbux/28694a64941290644a22 to your computer and use it in GitHub Desktop.

Reference:

https://docs.strongloop.com/display/public/LB/AngularJS+JavaScript+SDK#AngularJSJavaScriptSDK-Read(querying) https://docs.strongloop.com/display/public/LB/Where+filter

Get all projects
Project.find().$promise.then(function(data){
  console.log(data)
})
Create record attaching userId
User.me().$promise.then(function (userData) {
  Project.create({
    userId: userData.profile.id,
    name: 'test2',
    meta: {
      name: 'test2',
      description: 'test2 description',
      title: 'test2title',
    }
  }).$promise.then(function(data){
    console.log(data)
  })
})
Find with filter
Project.find({
 filter: {
    where: {
      name: 'test2'
    }
  }
}).$promise.then(function(data){
  console.log(data)
})
Update Record
$scope.project = Project.findOne({
 filter: {
    where: {
      name: 'test2'
    }
  }
}).$promise.then(function(data){
  self.theProject = data
})

$scope.saveme = function(d){
  d.name = 'test3';
  d.$save();
}
Another method for update
Project.upsert({
  "id" : "55dad5a30cd982ba6401b051",
  "name" : "test3",
  "meta" : {
      "name" : "test2",
      "description" : "Add a description to test2 project",
      "email" : "[email protected]",
      "owner" : "github.toroio-client"
  }
}).$promise.then(function(data){
  console.log(data)
})

//<button name="thebutton" ng-click="saveme(coderProjectsList.theProject)">The Button</button>

Delete Record

Project.deleteById({ id: '55dbb8a9d3033fdc5d6610d6' })
.$promise
.then(function() { console.log('deleted'); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment