Skip to content

Allow functions to be defined as the defaultValue, to return a scalar value #319

Description

@MrSwitch

In order to generate random numbers, hashes etc, as well as allow values to be derived from another value allow the defaultValue property to be a handler function which takes the current operation and assigns a value to it.

i.e...

// Member
const member = {
	schema: {
		name: {
			[method]: { // i.e. 'post'
				defaultValue(item) {
					return `${item.firstName} ${item.lastName}`;
				}
			}
		}
	}
};

const dare = new Dare({models: {member}});

// Post
await dare.post('member', {
	firstName: 'Andrew',
	lastName: 'Dodson',
});

// # Generates the query...
// INSERT INTO member (firstName, lastName, name)
// VALUES ('Andrew', 'Dodson', 'Andrew Dodson');

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions