-
Notifications
You must be signed in to change notification settings - Fork 16
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
JSON columns dont appear to be working #149
Comments
Upon further investigation, when using the JSON column type the generated SQL query should be
Note the |
There is no good solution to this. |
I noticed that in Connection.php, here - laravel-spanner/src/Connection.php Line 319 in 724159a
I can do this, and it works: $types = ['p0' => Database::TYPE_JSON];
$rowCount = $transaction->executeUpdate($query, ['parameters' => $bindings, 'types' => $types]); Of course this is just me manually typing a particular binding, but surely there is some way, perhaps by assigning something other than a string to the Model, which laraval-spanner can then intercept before it gets converted into a string, and once its been intercepted it can know to add the |
Spanner didn't have JSON types initially (2019) and we just stored JSON as STRING(MAX). I'll update the docs to say it's not supported for the moment. |
PR is always welcome btw. |
I haven't dealt with custom database/eloquent drivers before so its hard to follow the chain of how data is set/escaped before being passed to the I am trying to work out how the I was thinking perhaps if you pass an associative array, the But in my experimenting it doesnt even seem that the laravel-spanner/src/Connection.php Line 319 in 724159a
|
From what I can recall, |
That could potentially work but you might need to pass it as an object instead since empty arrays can't be treated as assoc array. |
Im really struggling to work out how to intercept the query generation to insert the relevant types. What I have so far is on the Model I have added a Then I have added this to the Builder protected $types = [];
public function setTypes($types)
{
$this->types = $types;
return $this;
} And in the model, I have overridden the public function newModelQuery()
{
return parent::newModelQuery()->setTypes($this->types);
} So now every Builder for a given Model has a When the query values are converted into bindings $types = [ 'pX' => Database::TYPE_X, 'pY' => Database::TYPE_Y; But for the life of me I cant figure out where to do that |
The solution is a custom Cast with a custom ValueInterface, as per this comment Should add this to the docs |
I have a model with a json column. As usual I have
$casts = ['json_column' => 'array']
in the model definition, but for some reason every time I try to save/update the model I get this errorThe text was updated successfully, but these errors were encountered: