Socket
Socket
Sign inDemoInstall

ember-data

Package Overview
Dependencies
Maintainers
13
Versions
737
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-data

The lightweight reactive data library for JavaScript applications


Version published
Weekly downloads
70K
decreased by-39.48%
Maintainers
13
Weekly downloads
 
Created

What is ember-data?

Ember Data is a library for robustly managing model data in Ember.js applications. It provides a consistent way to interact with a backend data store, manage relationships between models, and handle data persistence.

What are ember-data's main functionalities?

Defining Models

Ember Data allows you to define models with attributes and relationships. In this example, a `Post` model is defined with attributes `title` and `publishedAt`, and relationships to `author` and `comments`.

import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default class Post extends Model {
  @attr('string') title;
  @attr('date') publishedAt;
  @belongsTo('author') author;
  @hasMany('comment') comments;
}

Fetching Records

You can fetch records from the backend using the `store` service. This example demonstrates how to fetch a `post` record by its ID in a route.

import Route from '@ember/routing/route';

export default class PostRoute extends Route {
  async model(params) {
    return this.store.findRecord('post', params.post_id);
  }
}

Saving Records

Ember Data provides methods to save records back to the backend. This example shows how to save a `post` record.

import Controller from '@ember/controller';

export default class PostController extends Controller {
  async savePost(post) {
    await post.save();
  }
}

Handling Relationships

Ember Data makes it easy to handle relationships between models. This example demonstrates fetching a `post` along with its related `comments`.

import Route from '@ember/routing/route';

export default class PostRoute extends Route {
  async model(params) {
    let post = await this.store.findRecord('post', params.post_id);
    let comments = await post.comments;
    return { post, comments };
  }
}

Other packages similar to ember-data

Keywords

FAQs

Package last updated on 14 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc