Accessing Database

Hello everyone,
I am new to Wix and I am trying to get some things down so I would like your help.

I have some Collections and I want to make some generic function either in backend or public to access my Collections and I just can’t get it right.

so i have this very simple function :

export function SelectBasicInfo(mySearchValue)  {
	var myReturnValue,
		myBirthDay,
		myFullName ;
     
	wixData.query('People')
		.contains('title',mySearchValue)
		.find()
		.then(results => {
				myBirthDay  = results.items[0].birthday.getFullYear();
				myFullName  = results.items[0].name + ' ' + results.items[0].surname;
				
				myReturnValue = myFullName + ' ' + myBirthDay;
				return(myReturnValue);
		});
}

what troubles me is, that when i take the function code and just run in straight to ‘$w.onReady’ it works and returns the results i am expecting. when i call it as a function, i get undefined or no results. I don’t seem to understand why this happens, i ve made some other functions with just simple math and values to return just to test that i am not doing something wrong but they seem to return values just fine.

PS. I use all the necessery imports and i don’t get any errors.

Thank you.

I think you might be running into troubles with Promises. Try reading this article. I think it will help.

Oh now I understand… I never worked with asynchronus coding and really felt like total amateur while trying to get these functions to work and failed :P.

Thanks a lot!