Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MrSwitch opened this issue Jan 11, 2024 · 0 comments
Assignees

Comments

@MrSwitch
Copy link
Member

MrSwitch commented Jan 11, 2024

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');
@MrSwitch MrSwitch self-assigned this Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant