json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Bulk insert

Open r4lphio opened this issue 9 years ago • 0 comments

I'd like to do a bulk insert. This is possible with lowdb, but it doesn't appear to be a 1-to-1 for swap with what json-server expects from insert.

Updating the create method to use concat as shown here does enable bulk inserts. However, some tests fail just making that change so I'm creating an issues for discussion.

Example - use concat for create

function create (req, res, next) {
    const resource = db
      .get(name)
      .concat(req.body)
      .value()
    db.set(name, resource).write()

    res.setHeader('Access-Control-Expose-Headers', 'Location')
    res.location(`${getFullURL(req)}/${resource.id}`)

    res.status(201)
    res.locals.data = resource

    next()
  }

r4lphio avatar Feb 21 '17 18:02 r4lphio