@@ -4,6 +4,28 @@ use std::fmt::Debug;
44use std:: ops:: Range ;
55use std:: { borrow:: Borrow , ops:: Deref } ;
66
7+ /// Represents a database object (table, function, etc.)
8+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
9+ pub struct DatabaseObject < ' a > {
10+ /// Optional schema name
11+ pub schema : Option < & ' a str > ,
12+ /// Object name (required)
13+ pub name : & ' a str ,
14+ /// Optional object type (e.g., "table", "function", "view")
15+ pub object_type : Option < & ' a str > ,
16+ }
17+
18+ /// Owned version of DatabaseObject for use in diagnostic structs
19+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
20+ pub struct DatabaseObjectOwned {
21+ /// Optional schema name
22+ pub schema : Option < String > ,
23+ /// Object name (required)
24+ pub name : String ,
25+ /// Optional object type (e.g., "table", "function", "view")
26+ pub object_type : Option < String > ,
27+ }
28+
729/// Represents the location of a diagnostic in a resource.
830#[ derive( Debug , Default , Clone , Copy ) ]
931pub struct Location < ' a > {
@@ -12,8 +34,8 @@ pub struct Location<'a> {
1234 /// An optional range of text within the resource associated with the
1335 /// diagnostic.
1436 pub span : Option < TextRange > ,
15- /// An optional tuple identifying a database object
16- pub database_object : Option < ( Option < & ' a str > , & ' a str ) > ,
37+ /// An optional database object reference
38+ pub database_object : Option < DatabaseObject < ' a > > ,
1739 /// The optional source code of the resource.
1840 pub source_code : Option < BorrowedSourceCode < ' a > > ,
1941}
@@ -201,7 +223,7 @@ pub struct LocationBuilder<'a> {
201223 resource : Option < Resource < & ' a str > > ,
202224 span : Option < TextRange > ,
203225 source_code : Option < BorrowedSourceCode < ' a > > ,
204- database_object : Option < ( Option < & ' a str > , & ' a str ) > ,
226+ database_object : Option < DatabaseObject < ' a > > ,
205227}
206228
207229impl < ' a > LocationBuilder < ' a > {
@@ -358,30 +380,34 @@ impl AsSourceCode for String {
358380
359381/// Utility trait for types that can be converted into a database object reference
360382pub trait AsDatabaseObject {
361- fn as_database_object ( & self ) -> Option < ( Option < & ' _ str > , & ' _ str ) > ;
383+ fn as_database_object ( & self ) -> Option < DatabaseObject < ' _ > > ;
362384}
363385
364386impl < T : AsDatabaseObject > AsDatabaseObject for Option < T > {
365- fn as_database_object ( & self ) -> Option < ( Option < & ' _ str > , & ' _ str ) > {
387+ fn as_database_object ( & self ) -> Option < DatabaseObject < ' _ > > {
366388 self . as_ref ( ) . and_then ( T :: as_database_object)
367389 }
368390}
369391
370392impl < T : AsDatabaseObject + ?Sized > AsDatabaseObject for & ' _ T {
371- fn as_database_object ( & self ) -> Option < ( Option < & ' _ str > , & ' _ str ) > {
393+ fn as_database_object ( & self ) -> Option < DatabaseObject < ' _ > > {
372394 T :: as_database_object ( * self )
373395 }
374396}
375397
376- impl AsDatabaseObject for ( Option < & str > , & str ) {
377- fn as_database_object ( & self ) -> Option < ( Option < & ' _ str > , & ' _ str ) > {
378- Some ( ( self . 0 , self . 1 ) )
398+ impl < ' a > AsDatabaseObject for DatabaseObject < ' a > {
399+ fn as_database_object ( & self ) -> Option < DatabaseObject < ' _ > > {
400+ Some ( * self )
379401 }
380402}
381403
382- impl AsDatabaseObject for ( Option < String > , String ) {
383- fn as_database_object ( & self ) -> Option < ( Option < & ' _ str > , & ' _ str ) > {
384- Some ( ( self . 0 . as_deref ( ) , self . 1 . as_str ( ) ) )
404+ impl AsDatabaseObject for DatabaseObjectOwned {
405+ fn as_database_object ( & self ) -> Option < DatabaseObject < ' _ > > {
406+ Some ( DatabaseObject {
407+ schema : self . schema . as_deref ( ) ,
408+ name : & self . name ,
409+ object_type : self . object_type . as_deref ( ) ,
410+ } )
385411 }
386412}
387413
0 commit comments