Code Monkey home page Code Monkey logo

Comments (9)

thosakwe avatar thosakwe commented on June 12, 2024

Sounds good, will add this to next build.

Edit: Actually not sure this would be possible. You'll have to use a callback. In the next build, I'll add an app and service argument to be passed to callbacks, so you will be able to do this:

const cfg = {
  path: 'users':

  callback(user, seed, app, service) {
    return service.patch(user._id, {
      email: `user_${user._id}@myservice.com`
    });
  }
};

from feathers-seeder.

thosakwe avatar thosakwe commented on June 12, 2024

Ah, I see what you mean, index is related to count. I'll add that as well.

from feathers-seeder.

eikaramba avatar eikaramba commented on June 12, 2024

Wow what a quick response, respect :) I thought about implementing it myself, but wanted to first create a ticket.

Anyway, thx and yes {{index}} is just the iterator number of the count loop.

from feathers-seeder.

jamesholcomb avatar jamesholcomb commented on June 12, 2024

I think you could do this with template functions [#11] now:

let index = 0;
const counter = () => ++index;

const template = {
  email: () => `user_${counter()}@myservice.com`
}

Give it a try and let us know.

from feathers-seeder.

eikaramba avatar eikaramba commented on June 12, 2024

Interestingly it works in this case.

path: 'users',
delete: false,
randomize: false,
templates: [{
   id: counter(),
   group: 'user',
   email: '[email protected]',
   birthday: 1990,
   password: 'test123'
  }, {
   id: counter(),
   group: 'user',
   email: '{{internet.email}}',
   birthday: 1990,
   password: 'test123'
}],

but not in this case:

path: 'users',
count: 3,
delete: false,
template: {
id: counter(),
group: 'user',
email: '{{internet.email}}',
birthday: () => Math.floor(Math.random() * 100) + 1900,
gender: '{{random.boolean}}',
password: 'test123'

Here it is always the same value.

from feathers-seeder.

jamesholcomb avatar jamesholcomb commented on June 12, 2024

It's because you passed the result of a function call.

Use counter or an arrow function per the example.

from feathers-seeder.

eikaramba avatar eikaramba commented on June 12, 2024

i'm silly, sry you're right. Just strange that it worked in the above example.

from feathers-seeder.

thosakwe avatar thosakwe commented on June 12, 2024

So, can this issue be closed?

from feathers-seeder.

eikaramba avatar eikaramba commented on June 12, 2024

Well to be honest it can still be improved, just using {{index}} would be really great, but as a workaround this is legitimate. Maybe referecing this in the documentation at least.

from feathers-seeder.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.