github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/parser/model/ddl.go (about)

     1  // Copyright 2022 zGraph Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package model
    16  
    17  // GraphInfo provides meta data describing a graph.
    18  type GraphInfo struct {
    19  	ID         int64           `json:"id"`
    20  	Name       CIStr           `json:"name"`
    21  	Indexes    []*IndexInfo    `json:"indexes"`
    22  	NextPropID uint16          `json:"next_prop_id"`
    23  	Query      string          `json:"query"`
    24  	Labels     []*LabelInfo    `json:"-"`
    25  	Properties []*PropertyInfo `json:"-"`
    26  }
    27  
    28  // IndexInfo provides meta data describing a index.
    29  type IndexInfo struct {
    30  	ID         int64   `json:"id"`
    31  	Name       CIStr   `json:"name"`
    32  	Properties []CIStr `json:"properties"`
    33  	Query      string  `json:"query"`
    34  }
    35  
    36  // LabelInfo provides meta data describing a label.
    37  type LabelInfo struct {
    38  	ID    int64  `json:"id"`
    39  	Name  CIStr  `json:"name"`
    40  	Query string `json:"query"`
    41  }
    42  
    43  type PropertyInfo struct {
    44  	ID   uint16 `json:"id"`
    45  	Name CIStr  `json:"name"`
    46  }
    47  
    48  func (info *GraphInfo) Clone() *GraphInfo {
    49  	cloned := *info
    50  	cloned.Indexes = make([]*IndexInfo, len(info.Indexes))
    51  	for i := range info.Indexes {
    52  		cloned.Indexes[i] = info.Indexes[i].Clone()
    53  	}
    54  	cloned.Labels = make([]*LabelInfo, len(info.Labels))
    55  	for i := range info.Labels {
    56  		cloned.Labels[i] = info.Labels[i].Clone()
    57  	}
    58  	cloned.Properties = make([]*PropertyInfo, len(info.Properties))
    59  	for i := range info.Properties {
    60  		cloned.Properties[i] = info.Properties[i].Clone()
    61  	}
    62  	return &cloned
    63  }
    64  
    65  func (info *IndexInfo) Clone() *IndexInfo {
    66  	cloned := *info
    67  	cloned.Properties = make([]CIStr, len(info.Properties))
    68  	for i := range info.Properties {
    69  		cloned.Properties[i] = info.Properties[i]
    70  	}
    71  	return &cloned
    72  }
    73  
    74  func (info *LabelInfo) Clone() *LabelInfo {
    75  	cloned := *info
    76  	return &cloned
    77  }
    78  
    79  func (info *PropertyInfo) Clone() *PropertyInfo {
    80  	cloned := *info
    81  	return &cloned
    82  }