your1/laravel-sparql
Composer 安装命令:
composer require your1/laravel-sparql
包简介
A SPARQL based Eloquent model and Query builder for Laravel
README 文档
README
A lean, production-ready Laravel Eloquent adapter for SPARQL triple stores. Query and manage RDF data using familiar Laravel patterns.
Overview
Laravel SPARQL brings the power of RDF triple stores to Laravel with an Eloquent-style interface that feels native to Laravel developers. Built on the original Illuminate Database package by Taylor Otwell.
Key Features
- Familiar Eloquent API - Use standard Laravel patterns like
where(),get(),first(),save(),delete() - Analytical Queries (v1.2.3+) - Build complex queries with custom SELECT expressions, BIND clauses, and GROUP BY
- Hybrid Approach - Scalars for single values, arrays for multi-values (no unnecessary Collections)
- RDF Extensions - Language tags, multi-valued properties, and URI mappings when you need them
- Batch Operations - Efficient bulk insert/update/delete operations
- Sync Trait - Easily sync regular Eloquent models to SPARQL endpoints
- Multi-Tenancy Support - Full support for stancl/tenancy with automatic endpoint switching per tenant
- No Magic - Explicit model definitions, no dynamic class generation
- Production Ready - 514 passing tests, optimized for performance
Requirements
- PHP 8.2+
- Laravel 12.0+
- A SPARQL 1.1 compliant endpoint with Graph Store Protocol support
- ✅ Apache Jena Fuseki
- ✅ Blazegraph
- ✅ Amazon Neptune
- ✅ GraphDB
- ✅ Virtuoso
- ✅ Most modern SPARQL stores
Note: This package uses the W3C SPARQL 1.1 Graph Store HTTP Protocol for efficient bulk operations. This is a standard feature in modern SPARQL endpoints.
Installation
Install via Composer:
composer require your1/laravel-sparql
The service provider will automatically register a sparql database driver with Laravel's database manager.
Quick Start
1. Configure Your SPARQL Endpoint
Add to config/database.php:
'connections' => [ 'sparql' => [ 'driver' => 'sparql', 'endpoint' => env('SPARQL_ENDPOINT', 'http://localhost:3030/test/sparql'), // IMPORTANT: Specify your triple store implementation 'implementation' => env('SPARQL_IMPLEMENTATION', 'fuseki'), // fuseki|blazegraph|generic 'auth' => [ 'type' => 'digest', 'username' => env('SPARQL_USERNAME'), 'password' => env('SPARQL_PASSWORD'), ], 'namespaces' => [ 'schema' => 'http://schema.org/', 'foaf' => 'http://xmlns.com/foaf/0.1/', ], ], ],
Implementation Options:
fuseki- Apache Jena Fuseki (default)blazegraph- Blazegraph triple storegeneric- W3C standard (Virtuoso, GraphDB, Stardog, Amazon Neptune, etc.)
Add to .env:
SPARQL_ENDPOINT=http://localhost:3030/test/sparql SPARQL_IMPLEMENTATION=fuseki
2. Define a Model
use LinkedData\SPARQL\Eloquent\Model; class Person extends Model { protected $connection = 'sparql'; protected $table = 'http://schema.org/Person'; protected $propertyUris = [ 'name' => 'http://schema.org/name', 'email' => 'http://schema.org/email', 'age' => 'http://schema.org/age', ]; protected $fillable = ['name', 'email', 'age']; protected $casts = ['age' => 'integer']; }
3. Start Using It
// Create $person = new Person(); $person->id = 'http://example.com/person/1'; $person->name = 'John Doe'; $person->email = 'john@example.com'; $person->save(); // Query $adults = Person::where('age', '>', 18)->get(); $john = Person::where('name', 'John')->first(); // Update $person->age = 31; $person->save(); // Delete $person->delete(); // Analytical queries (v1.2.3+) use LinkedData\SPARQL\Query\Expression; $labelStats = DB::connection('sparql') ->query() ->selectExpression('?language') ->selectExpression('(COUNT(?label) as ?count)') ->whereTriple('?concept', 'skos:inScheme', Expression::iri($schemeUri)) ->whereTriple('?concept', 'skos:prefLabel', '?label') ->bind('COALESCE(LANG(?label), "no-lang")', '?language') ->groupBy('?language') ->get();
What's New in v1.2.3
Analytical Query Support - Build sophisticated SPARQL queries with Laravel's fluent syntax:
selectExpression()- Custom SELECT with aggregates and computed valueswhereTriple()- Explicit triple patterns with namespace supportbind()- BIND expressions for computed values- Enhanced
groupBy()for SPARQL variables
See Usage Guide - Analytical Queries for examples.
Documentation
For comprehensive guides and examples, see:
- Usage Guide - Core concepts, CRUD operations, queries, RDF features, batch operations, and syncing regular Eloquent models
- Multi-Tenancy Guide - Complete guide for integrating with stancl/tenancy for multi-tenant applications
- API Reference - Complete API documentation for all classes and methods
- Development Guide - Setup, testing, and development instructions
Philosophy
- Simple is Better - Minimal complexity, maximum clarity
- No Magic - Explicit over implicit, predictable behavior
- Performance First - Optimized for production workloads
- Laravel Native - Feels like standard Eloquent
Credits
Original Author: Roberto Guido - Created the foundational Laravel SPARQL adapter and maintained it as part of the Solid Data Workers project.
Original Repository: https://gitlab.com/solid-data-workers/laravel-sparql
Original Licenses: MIT License and Creative Commons Attribution 3.0 Unported
This fork preserves all original copyright and attribution while adding significant enhancements and modernizations.
Built on Laravel's Illuminate Database package by Taylor Otwell.
License
MIT License. See LICENSE for details.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
your1/laravel-sparql 适用场景与选型建议
your1/laravel-sparql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 222 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「model」 「laravel」 「RDF」 「sparql」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 your1/laravel-sparql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 your1/laravel-sparql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 your1/laravel-sparql 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Interfaces for web resource models and services to retrieve and create them
A PSR-7 compatible library for making CRUD API endpoints
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 222
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-24