How to use @aws-amplify/datastore - 8 common examples

To help you get started, we’ve selected a few @aws-amplify/datastore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabit3 / amplify-datastore-example / src / App.js View on Github external
async function query() {
    const posts = await DataStore.query(Post);
    console.log('posts: ', posts)
    const original = await DataStore.query(Post, "4d5a08f3-d0ac-42bd-a19e-170991a4d79b");

    // await DataStore.save(
    //   Post.copyOf(original, updated => {
    //     updated.title = `title ${Date.now()}`;
    //     updated.status = PostStatus.ACTIVE
    //   })
    // );
  }
  async function create() {
github dabit3 / amplify-datastore-example / src / App.js View on Github external
async function query() {
    const posts = await DataStore.query(Post);
    console.log('posts: ', posts)
    const original = await DataStore.query(Post, "4d5a08f3-d0ac-42bd-a19e-170991a4d79b");

    // await DataStore.save(
    //   Post.copyOf(original, updated => {
    //     updated.title = `title ${Date.now()}`;
    //     updated.status = PostStatus.ACTIVE
    //   })
    // );
  }
  async function create() {
github dabit3 / amplify-datastore-example / src / App.js View on Github external
async function create() {
    const postData = {...form, status: PostStatus.INACTIVE}
    await DataStore.save(
      new Post(postData)
    );
    console.log('successfully created new post')
    updateForm({ title: '', rating: '' })
  }
  useEffect(() => {
github sebsto / amplify-datastore-js-e2e / src / App.js View on Github external
useEffect( () => {
    
    const subscription = DataStore.observe(Post).subscribe(msg => {
      console.log(msg.model, msg.opType, msg.element);
      listPosts(setPosts);
    });

    const handleConnectionChange = () => {
      const condition = navigator.onLine ? 'online' : 'offline';
      console.log(condition);
      if (condition === 'online') { listPosts(setPosts); }
    }
    
    window.addEventListener('online', handleConnectionChange);
    window.addEventListener('offline', handleConnectionChange);
       
    return () => subscription.unsubscribe();
  }, []);
github sebsto / amplify-datastore-js-e2e / src / App.js View on Github external
async function onQuery(setPosts) {
  const posts = await DataStore.query(Post, c => c.rating("gt", 4));
  setPosts(posts)
}
github sebsto / amplify-datastore-js-e2e / src / App.js View on Github external
async function listPosts(setPosts) {
  const posts = await DataStore.query(Post, Predicates.ALL);
  setPosts(posts);
}
github sebsto / amplify-datastore-js-e2e / src / App.js View on Github external
function onCreate() {
  DataStore.save(
    new Post({
      title: `New title ${Date.now()}`,
      rating: (function getRandomInt(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
      })(1, 7),
      status: PostStatus.ACTIVE
    })
  );
}
github sebsto / amplify-datastore-js-e2e / src / App.js View on Github external
function onDeleteAll() {
  DataStore.delete(Post, Predicates.ALL);
}

@aws-amplify/datastore

AppSyncLocal support for aws-amplify

Apache-2.0
Latest version published 8 days ago

Package Health Score

98 / 100
Full package analysis

Similar packages