目录

Importing an Object Type File

Constraints

This feature supports phones and tablets by default. Starting from version 5.1.0(18), support for wearables is added. From version 5.1.1(19), TVs are also supported. From version 6.1.0(23), PCs/2-in-1 devices are supported as well.

Prerequisites

Procedure

  1. Name the exported JSON file schema.json and copy it to the AppScope/resources/rawfile or entry/src/main/resources/rawfile directory of the DevEco Studio project. During compilation and build, resource files in the AppScope directory are merged into the module's resource files. For details, please refer to Resource Categories.

  2. Create the BookInfo.ets file in the entry/src/main/ets/model directory of the code project based on the object type BookInfo created in AppGallery Connect. The sample code in the file is as follows:

    The mapping between types of fields created in AppGallery Connect and ArkTS data types is as follows:

    • String and Text: string

    • Boolean: boolean

    • Byte and ByteArray: Uint8Array

    • Short, Integer, Long, Float, Double, IntAutoIncrement, and LongAutoIncrement: number

    • Date: Date

    import { cloudDatabase } from '@kit.CloudFoundationKit';
    
    class BookInfo extends cloudDatabase.DatabaseObject {
      public naturalbase_ClassName(): string {
        return 'BookInfo';
      }
    
      public id: number | undefined;
      public bookName: string | undefined;
      public author: string | undefined;
      public price: number | undefined;
      public borrowerId: number | undefined;
      public borrowerName: string | undefined;
      public borrowerTime: Date | undefined;
    }
    
    export { BookInfo };