Sesi bersamaan di IRIS: SQL, Objek, REST, GraphQL
βDan kesalahpahaman Anda sangat wajar. Bagaimana seseorang yang selalu bepergian dalam pesta koktail memahami perasaan dan kesan bepergian dengan mengungkapkan atau terbang di udara "
Kazimir Malevich (1916)
, API SQL/REST/GraphQL, /:
;
;
, , ;
, β :
, API , .
, API, . , .
, , , HDD , , - SSD. , HDD/SSD.
, // . HDD β / . SSD β . β , . , / . .
, β HDD/SSD. β , , , , . , , // , .
, . . , InterSystems IRIS, β . , .
, IRIS. β - ObjectScript API. , , SQL ObjectScript. API ObjectScript.
- "SQL Zoo", SQL. API.
API , API, https://github.com/public-apis/public-apis
SQL
SQL. ?
SQL . https://sqlzoo.net. SQL , .
SQLZoo IRIS .
InterSystems IRIS ? β InterSystems IRIS Community Edition β InterSystems IRIS Data Platform
InterSystems IRIS Community Edition .
SQLZoo IRIS. :
( , , http://localhost:52773/csp/sys/UtilHome.csp),
USER - Namespace %SYS Switch USER
> SQL - , SQL .
" " "" - .
, , , SQL IRIS, Visual Studio Code SQLTools "SQLTools Driver for InterSystems IRIS". .
World:
http://sqlzoo.net/w/index.php?title=Createworld.txt&action=raw a script to create the world database
http://sqlzoo.net/w/index.php?title=Tabworld.txt&action=raw the data to go in that table
IRIS " ".
CREATE TABLE world(
name VARCHAR(50) NOT NULL
,continent VARCHAR(60)
,area DECIMAL(10)
,population DECIMAL(11)
,gdp DECIMAL(14)
,capital VARCHAR(60)
,tld VARCHAR(5)
,flag VARCHAR(255)
,PRIMARY KEY (name)
)
" " > . , , β .
" ":
SELECT * FROM world
"SQL Zoo". SQL :
SELECT population
FROM world
WHERE name = 'France'
API SQLZoo IRIS.
β , "" SQL SQL ObjectScript β - , IRIS.
Class User.worldquery
{
ClassMethod WhereName(name As %String)
{
&sql(
SELECT population INTO :population
FROM world
WHERE name = :name
)
IF SQLCODE<0 {WRITE "SQLCODE error ",SQLCODE," ",%msg QUIT}
ELSEIF SQLCODE=100 {WRITE "Query returns no results" QUIT}
WRITE name, " ", population
}
}
:
do ##class(User.worldquery).WhereName("France")
.
/
REST/GraphQL. API . - , - . : Spring Java/Kotlin, Django Python, Rails Ruby, ASP.NET C# Angular TypeScript. ObjectScript, IRIS.
? , , . , . , API, . . , / , .
, / . ? SQL/REST/GraphQL API . , , β , , .
. β IRIS.
SQL IRIS, :
- () |
(SQL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
, join |
( ) |
( ) |
IRIS.
SQL world , IRIS β User.world.
Class User.world Extends %Persistent [ ClassType = persistent, DdlAllowed, Final, Owner = {_SYSTEM}, ProcedureBlock, SqlRowIdPrivate, SqlTableName = world ]
{
Property name As %Library.String(MAXLEN = 50) [ Required, SqlColumnNumber = 2 ];
Property continent As %Library.String(MAXLEN = 60) [ SqlColumnNumber = 3 ];
Property area As %Library.Numeric(MAXVAL = 9999999999, MINVAL = -9999999999, SCALE = 0) [ SqlColumnNumber = 4 ];
Property population As %Library.Numeric(MAXVAL = 99999999999, MINVAL = -99999999999, SCALE = 0) [ SqlColumnNumber = 5 ];
Property gdp As %Library.Numeric(MAXVAL = 99999999999999, MINVAL = -99999999999999, SCALE = 0) [ SqlColumnNumber = 6 ];
Property capital As %Library.String(MAXLEN = 60) [ SqlColumnNumber = 7 ];
Property tld As %Library.String(MAXLEN = 5) [ SqlColumnNumber = 8 ];
Property flag As %Library.String(MAXLEN = 255) [ SqlColumnNumber = 9 ];
Parameter USEEXTENTSET = 1;
/// Bitmap Extent Index auto-generated by DDL CREATE TABLE statement. Do not edit the SqlName of this index.
Index DDLBEIndex [ Extent, SqlName = "%%DDLBEIndex", Type = bitmap ];
/// DDL Primary Key Specification
Index WORLDPKey2 On name [ PrimaryKey, Type = index, Unique ];
}
- . ObjectScript, . , , SQL-.
, SQL, User.world WhereName, " " :
ClassMethod WhereName(name As %String) As User.world
{
Set id = 1
While ( ..%ExistsId(id) ) {
Set countryInfo = ..%OpenId(id)
if ( countryInfo.name = name ) { Return countryInfo }
Set id = id + 1
}
Return countryInfo = ""
}
:
set countryInfo = ##class(User.world).WhereName("France")
write countryInfo.name
write countryInfo.population
, , IRIS WORLDPKey2 / :
set countryInfo = ##class(User.world).WORLDPKey2Open("France")
:
write countryInfo.name
write countryInfo.population
, IRIS , Java, Python, , C# (.Net), JavaScript , , Julia [1][2]. .
-API.
REST RESTful -API
. β . , http. IRIS " " http- Apache.
Representational state transfer (REST) β , , -. , , . REST - , http/https. , / - SOAP XML-RPC.
ID REST URL .
- IRIS http://localhost:52773 /world/ /world/France.
-:
http://localhost:52773/world/France
IRIS . , REST API OpenAPI 2.0.
β API . REST-, IRIS:
- URL, %CSP.REST
- - IRIS
1 -
/// Description
Class User.worldrest Extends %CSP.REST
{
Parameter UseSession As Integer = 1;
Parameter CHARSET = "utf-8";
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/:name" Method="GET" Call="countryInfo" />
</Routes>
}
}
- , :
ClassMethod countryInfo(name As %String) As %Status
{
set countryInfo = ##class(User.world).WhereName(name)
write "Country: ", countryInfo.name
write "<br>"
write "Population: ", countryInfo.population
return $$$OK
}
, REST- name - ":name".
2 - IRIS
System Administration > Security > Applications > Web Applications
- URL /world β - worldrest.
- http://localhost:52773/world/France ( , ).
β ( ). https://community.intersystems.com/post/debugging-web
"401 Unauthorized", , - , - %All "Application Roles". , .
GraphQL
, , IRIS API GraphQL . .
GraphQL .
API. , , , REST- -API. GraphQL Linux . .
InterSystems GraphQL IRIS 2018 .
En: GraphQL , ,
GraphQL β IRIS , . , - GraphQL GraphiQL.
, IRIS -. - GraphQL REST- :
GraphiQL β , HTML JavaScript:
http://localhost:52773/graphiql/index.html
, , . , . .
GraphQL :
{
User_world ( name: France ) {
name
population
}
}
:
{
"data": {
"User_world": [
{
"name": "France",
"population": 65906000
}
]
}
}
:
|
|
|
SQL |
50 |
|
|
|
40 , |
|
REST |
20 |
|
GraphQL |
5 |
|
SQL, REST , , GraphQL . IRIS , , .
, API XML (SOAP) JSON IRIS . .
, API β , . , API , , .
,
Artikel ini disiapkan tidak hanya untuk membandingkan API modern dan, bahkan, tidak terlalu banyak untuk gambaran umum tentang kemampuan dasar IRIS. Pemrogram pemula akan bisa mendapatkan lebih banyak manfaat dari contoh di atas: lihat kemudahan beralih antar API saat mengakses database, mengambil langkah pertama di IRIS, dan mendapatkan hasil cepat untuk tugas mereka.
Dan oleh karena itu, pendapat Anda sangat menarik, apakah pendekatan ini membantu untuk "permulaan yang mudah", langkah-langkah proses apa yang menyulitkan pemula untuk menguasai alat bekerja dengan API di IRIS? Apa yang tampak seperti "hambatan yang tidak jelas"? Tanyakan kepada mereka yang menguasai IRIS dan tulislah kepada saya di kolom komentar. Saya pikir akan bermanfaat bagi semua orang untuk membahas ini.