JDBC Driver for JSON

Build 22.0.8479

スキーマのカスタマイズ

自動スキーマ検出 で検出されたテーブルスキーマをカスタマイズして、カラム名やデータ型を変更したり、更新機能を有効にしたりできます。CData JDBC Driver for JSON の処理操作は、データの処理およびリモートデータソースとの通信の複雑さを解決しながら、カスタムスキーマを介してこれらのレイヤーを制御することも可能です。

カスタムスキーマは、コンフィギュレーションファイルで定義されます。この章では、これらのファイルの構造を概説します。

スキーマの生成

スキーマ生成 を使用すると、自動スキーマ検出 で検出された動的スキーマを永続化およびカスタマイズできます。

スキーマファイルの編集

テーブルとビューは、APIScript でスキーマファイルを作成することによって定義されます。APIScript は、テーブルのカラムとその動作を定義するシンプルなAPIScript コンフィギュレーション言語にて書かれています。また、JSON を処理可能にするビルトインオペレーションがあります。これらのデータ処理構造に加えて、APIScript は、条件分岐やループなどに対応して構成されているフル機能の言語です。ただし、サンプルスキーマに示すように、ほとんどのテーブル定義ではこれらの機能を使用する必要はありません。

スキーマ例

以下は、Raw データ 例のpeople ドキュメントをモデル化し、SQL をローカルまたはリモートのJSON に実行するために必要なすべてのコンポーネントを含む、完全に機能的なテーブルスキーマです。

スキーマは次の接続文字列を反映します。これにより、指定されたXPaths によって記述されたデータを含む単一のテーブルが返されます。異なるDataModel 設定についてのガイドは、階層データの解析 を参照してください。

DataModel=FLATTENEDDOCUMENTS;URI=C:\people.xml;XPath='/root/people;/root/people/vehicles;/root/people/vehicles/maintenance';Location=C:\myschemas;GenerateSchemaFiles=OnStart;

スキーマの各コンポーネントの詳細は、カラム定義SELECT 実行INSERT 実行UPDATE 実行、およびDELETE 実行 で確認できます。ストアドプロシージャを作成して、SELECT、INSERT、UPDATE、またはDELETE ステートメントとしてモデル化できないAPI の機能を実装することもできます。詳しくは、ストアドプロシージャの定義 を参照してください。

<api:script xmlns:api="http://apiscript.com/ns?v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <api:info title="people" desc="Generated schema file." xmlns:other="http://apiscript.com/ns?v1">
    <!-- You can modify the name, type, and column size here. -->
    <!-- See Column Definitions to specify column behavior and use XPaths to extract column values from JSON. -->
    <attr name="date"                 xs:type="date"    readonly="false"              other:xPath="/json/people/vehicles/maintenance/date"     />
    <attr name="desc"                 xs:type="string"  readonly="false"              other:xPath="/json/people/vehicles/maintenance/desc"     />
    <attr name="insurance.company"    xs:type="string"  readonly="false"              other:xPath="/json/people/vehicles/insurance/company"    />
    <attr name="insurance.policy_num" xs:type="string"  readonly="false"              other:xPath="/json/people/vehicles/insurance/policy_num" />
    <attr name="maintenance:_id"      xs:type="string"  readonly="false"  key="true"  other:xPath="/json/people/vehicles/maintenance/_id"      />
    <attr name="model"                xs:type="string"  readonly="false"              other:xPath="/json/people/vehicles/model"                />
    <attr name="people:_id"           xs:type="string"  readonly="false"  key="true"  other:xPath="/json/people/_id"                           />
    <attr name="personal.age"         xs:type="integer" readonly="false"              other:xPath="/json/people/personal/age"                  />
    <attr name="personal.gender"      xs:type="string"  readonly="false"              other:xPath="/json/people/personal/gender"               />
    <attr name="personal.name.first"  xs:type="string"  readonly="false"              other:xPath="/json/people/personal/name/first"           />
    <attr name="personal.name.last"   xs:type="string"  readonly="false"              other:xPath="/json/people/personal/name/last"            />
    <attr name="source"               xs:type="string"  readonly="false"              other:xPath="/json/people/source"                        />
    <attr name="type"                 xs:type="string"  readonly="false"              other:xPath="/json/people/vehicles/type"                 />
    <attr name="vehicles:_id"         xs:type="string"  readonly="false"  key="true"  other:xPath="/json/people/vehicles/_id"                  />
  </api:info>

  <api:set attr="DataModel" value="FLATTENEDDOCUMENTS" />
  <api:set attr="URI" value="C:\\tmp\\people.json" />

  <api:set attr="JSONPath" value="$.people;$.people.vehicles;$.people.vehicles.maintenance" />

  <!-- The GET method corresponds to SELECT. Here you can change the parameters of the request for data. The results of processing are pushed to the schema's output. See SELECT Execution for more information. -->
  <api:script method="GET">
    <api:call op="jsonproviderGet">
      <api:push/>
    </api:call>
  </api:script>

  <!-- To add support for INSERTS please see the INSERT Execution page within the help for further information and examples. -->
  <api:script method="POST">
    <api:set attr="method" value="POST"/>
    <api:call op="jsonproviderGet">
      <api:throw code="500" desc="Inserts are not currently supported."/>
      <api:push/>
    </api:call>
  </api:script>

  <!-- To add support for UPDATES please see the UPDATE Execution page within the help for further information and examples. -->
  <api:script method="MERGE">
    <api:set attr="method" value="PUT"/>
    <api:call op="jsonproviderGet">
      <api:throw code="500" desc="Updates are not currently supported."/>
      <api:push/>
    </api:call>
  </api:script>

  <!-- To add support for DELETES please see the DELETE Execution page within the help for further information and examples. -->
  <api:script method="DELETE">
    <api:set attr="method" value="DELETE"/>
    <api:call op="jsonproviderGet">
      <api:throw code="500" desc="Deletes are not currently supported."/>
      <api:push/>
    </api:call>
  </api:script>

</api:script>

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479