0.1.4 • Published 7 years ago

@sanity/gradient-client v0.1.4

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

gradient-client

Javascript client for the Gradient document store. Works in both Node.js and modern browsers.

Installation

npm install @sanity/gradient-client

Usage

const gradient = require('@sanity/gradient-client')
const client = gradient({
  url: 'https://gradient.url:56200',
  dataset: 'beerfiesta',
  token: '[auth token here]'
})

// Fetching:
client.fetch(
  'beerfiesta.beer[rating > $ratingThreshold] {name, rating}',
  {$ratingThreshold: 95},
  (err, response) => {
    if (err) {
      throw err
    }

    response.result.forEach(beer => {
      console.log(`${beer.name} has a rating of ${beer.rating}`)
    })
  }
)

// Fetch a specific document by ID:
client.getDocument('beerfiesta/someId', (err, beer) => {
  if (err) {
    throw err
  }
  
  console.log(beer)
})

// Creating:
client.create({
  _type: 'beerfiesta.brewery',
  companyName: 'Bengler',
  location: {
    lat: 59.923868,
    lng: 10.757842
  }
}, (err, response) => {
  if (err) {
    throw err
  }

  console.log(`Document ID: ${response.results[0].id}`)
})

// Updating:
client.update(
  'beerfiesta/S0YNUJXt2Ko0yjIDnZ9T', // Document ID
  { // Update patch, see Gradient wiki for update operations
    companyName: 'Bengler AS',
    location: {
      lat: 59.9238681
    }
  },
  (err, response) => { /* handle it */ }
)

// Deleting:
client.delete(
  'beerfiesta/S0YNUJXt2Ko0yjIDnZ9T', // Document ID
  (err, response) => { /* handle it */ }
)

License

MIT-licensed. See LICENSE.

0.1.4

7 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago