ML 참조 - 데이터베이스


"데이터베이스" 속성

"database" 속성은 데이터베이스를 데이터 소스로 정의합니다. 다음과 같은 하위 속성이 있습니다.

Element Description
"connection" The name of a database connection
"execute" Array of SQL statements to be executed before data retrieval (optional)
"keyfield" The key field for the main table (optional)
"maintable" The main table for this application (optional)
"orderby" A fixed SQL orderby clause for the application (optional)
"sql" The SQL statement for retrieving data

데이터베이스의 데이터

이 모델은 SQL 데이터베이스의 Customer 테이블에서 Customer, City 및 Country를 포함하는 레코드를 가져옵니다.

예시

{
"database": {
    "connection": "mysql",
    "sql"       : "SELECT CustomerName, City, Country FROM Customers",
    "orderby"   : "CustomerName"
}
}

필터 제한

사용자가 데이터를 필터링할 수 있도록 모델에 필터 정보를 추가할 수 있습니다.

"filteritems" : [
    {"item" : "CustomerName", "label" : "Customer"},
    {"item" : "City"},
    {"item" : "Country"}]

분류 제한

사용자가 데이터를 정렬할 수 있도록 모델에 정렬 정보를 추가할 수 있습니다.

"sortitems" : [
    {"item" : "CustomerName", "label" : "Customer"},
    {"item" : "City"},
    {"item" : "Country"}]

업데이트 제한

사용자가 데이터를 업데이트할 수 있도록 모델에 업데이트 정보를 포함할 수 있습니다. 

예시

"updateItems" : [
    {"item" : "CustomerName"},
    {"item" : "Address"},
    {"item" : "PostalCode"},
    {"item" : "City"},
    {"item" : "Country"}]

기본적으로 AppML을 사용하면 모델에 지정된 데이터만 필터링, 정렬 또는 업데이트할 수 있습니다.


데이터베이스 연결

데이터베이스 연결은 appml_config.php 에 정의되어 있습니다 .

appml_config.php

<?php echo("Access Forbidden");exit();?>
{
"dateformat" : "yyyy-mm-dd",
"databases": [
    {
    "connection" : "mysql",
    "host"       : "127.0.0.1:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "googleDB",
    "host"       : "192.168.1.1:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "amazonDB",
    "host"       : "mydbinstance.amazon.com:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "azureDB",
    "host"       : "azure.cloudapp.net",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    }
]
}

구성 파일에는 많은 데이터베이스 연결이 포함될 수 있습니다.


데이터베이스 생성

AppML을 사용하면 애플리케이션이 시작되기 전에 SQL 문을 실행할 수 있으므로 필요한 경우 이를 사용하여 데이터베이스를 생성할 수 있습니다.

모델

{
"database" : {
"connection" : "myCDs",
"execute" : [
"DROP TABLE IF EXISTS CD_Catalog",
"CREATE TABLE IF NOT EXISTS CD_Catalog (CDID INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (CDID),Title NVARCHAR(255),Artist NVARCHAR(255),Country NVARCHAR(255),Price NUMBER)"
]
}}

신속한 프로토타이핑에 적합합니다!