Studioを使用したグラフ・スキーマの作成
DataStax StudioおよびGroovyを使用したグラフ・データベース・スキーマの作成。
グラフ・データベースのデータ・モデルの作成は、スキーマを作成するための重要な最初のステップです。データ・モデルを設計し、グラフを作成した後、グラフ・データベースの作成における次のステップは、頂点および辺ならびにそのプロパティのスキーマの定義です。Gremlin-Groovyを使用し、DataStax Studioのセルにスクリプトを入力します。
始める前に
手順
例
// レシピ・スキーマ
// Studioで実行する場合は、すべての行をセルにコピー&ペーストしてから実行します。
// Gremlin Consoleで実行する場合は、次の2行を使用します
// script = new File('/tmp/RecipeSchema.groovy').text; []
// :> @script
// プロパティ・キー
// ifNotExists()を使用して、作成済みのプロパティ・キーがあるかどうかを確認します。
schema.propertyKey('name').Text().ifNotExists().create()
schema.propertyKey('gender').Text().create()
schema.propertyKey('instructions').Text().create()
schema.propertyKey('category').Text().create()
schema.propertyKey('year').Int().create()
schema.propertyKey('timestamp').Timestamp().create()
schema.propertyKey('ISBN').Text().create()
schema.propertyKey('calories').Int().create()
schema.propertyKey('amount').Text().create()
schema.propertyKey('stars').Int().create()
schema.propertyKey('comment').Text().single().create() // single()はオプション(デフォルト)です
// 複数プロパティの例
// schema.propertyKey('nickname').Text().multiple().create();
// プロパティに追加されるメタプロパティの例:
// schema.propertyKey('livedIn').Text().create()
// schema.propertyKey('country').Text().properties('livedIn').create()
// 頂点ラベル
schema.vertexLabel('author').ifNotExists().create()
schema.vertexLabel('recipe').create()
// プロパティを含む頂点ラベルの作成例
// schema.vertexLabel('recipe').properties('name','instructions').create()
schema.vertexLabel('ingredient').create()
schema.vertexLabel('book').create()
schema.vertexLabel('meal').create()
schema.vertexLabel('reviewer').create()
// カスタム頂点IDの例:
// schema.propertyKey('city_id').Int().create()
// schema.propertyKey('sensor_id').Uuid().create()
// schema().vertexLabel('FridgeSensor').partitionKey('city_id').clusteringKey('sensor_id').create()
// 辺ラベル
schema.edgeLabel('authored').ifNotExists().create()
schema.edgeLabel('created').create()
schema.edgeLabel('includes').create()
schema.edgeLabel('includedIn').create()
schema.edgeLabel('rated').connection('reviewer','recipe').create()
// 頂点インデックス
// 二次インデックス
schema.vertexLabel('author').index('byName').secondary().by('name').add()
// マテリアライズド・インデックス
schema.vertexLabel('recipe').index('byRecipe').materialized().by('name').add()
schema.vertexLabel('meal').index('byMeal').materialized().by('name').add()
schema.vertexLabel('ingredient').index('byIngredient').materialized().by('name').add()
schema.vertexLabel('reviewer').index('byReviewer').materialized().by('name').add()
// サーチ
// schema.vertexLabel('recipe').index('search').search().by('instructions').asText().add()
// schema.vertexLabel('recipe').index('search').search().by('instructions').asString().add()
// 複数のプロパティ・キーにサーチ・インデックスが付いている場合
// schema.vertexLabel('recipe').index('search').search().by('instructions').asText().by('category').asString().add()
// 辺インデックス
schema.vertexLabel('reviewer').index('ratedByStars').outE('rated').by('stars').add()
// メタプロパティ'livedIn'を使用したプロパティ・インデックスの例:
// schema().vertexLabel('author').index('byLocation').property('country').by('livedIn').add()
// スキーマの説明
// スキーマが目的通りに構築されているかどうかをチェックするために使用します
schema.describe()