How to Map GridDB Data Types to Laravel Eloquent Models When Using the GridDB PHP Client? - Stack Overflow

I'm building a Laravel application where I need to store and retrieve data from GridDB. I've

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742367484a4430604.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信