admin管理员组文章数量:1334133
I'm building a Laravel application where I need to store and retrieve data from GridDB. I've successfully established a connection to GridDB and can perform basic operations like creating containers and inserting data.
However, I'm facing challenges with mapping GridDB data types to Eloquent model attributes.
What I've Done:
I have a container in GridDB with the following schema:
id (INTEGER)
sensor_id (STRING)
value (DOUBLE)
timestamp (TIMESTAMP)
Laravel Eloquent Model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SensorData extends Model
{
protected $table = 'sensor_data';
protected $primaryKey = 'id';
public $incrementing = false;
public $timestamps = false;
protected $fillable = [
'id',
'sensor_id',
'value',
'timestamp',
];
protected $casts = [
'id' => 'integer',
'sensor_id' => 'string',
'value' => 'double',
'timestamp' => 'datetime',
];
}
- Data Retrieval:
$data = SensorData::where('sensor_id', 'sensor_001')
->whereBetween('timestamp', [$startDate, $endDate])
->get();
and for this i get:
Undefined Table or Column:
Base table or view not found: 1146 Table 'mydatabase.sensor_data' doesn't exist
If I try to fetch data directly using the GridDB PHP client and map it to the model, I get errors related to data type mismatches, especially with the timestamp field.
How can I correctly map GridDB data types to Laravel Eloquent model attributes?
版权声明:本文标题:How to Map GridDB Data Types to Laravel Eloquent Models When Using the GridDB PHP Client? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742367484a2461579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论