Bulk Insert of historical data - how to access private members?
eugenefvdm opened this issue · 1 comments
Proposal to amend code to allow bulk inserts
I would like to do a bulk insert of historical data. This is trivial using Laravel's Query helper:
$client = Scheb\YahooFinanceApi\ApiClientFactory::createApiClient();
$historicalPricing = $client->getHistoricalQuoteData(
"msft",
Scheb\YahooFinanceApi\ApiClient::INTERVAL_1_DAY,
new \DateTime("-1 year"),
new \DateTime("today")
);
DB::table("share_price_histories")->insert($newArray);
However, since ->getHistoricalQuoteData
returns results as private members I'm lost as how to do it.
I could technically run for-next
loop and convert everything to a new array, and then insert it, but having the for-next
loop seems like a penalty.
I'm happy to do a pull request but I will need some guidance.
In theory one could make all the members as public
access but I guess this will break some programming discipline.
Any assistance will be appreciated on how I could go about doing this.
We could add a toArray
function returning all properties as an array.
A function
public function toArray(): array {
return get_object_vars($this);
}
should to the job and make it happen quite efficiently, as the data model only contains data fields and nothing else.
If we add this, it should be added to every model class (not only HistoricalData
).