Vier Datenbank-APIs

Gleichzeitige Sitzung in IRIS: SQL, Objekte, REST, GraphQL

Kasimir Malewitsch, Sportler (1932)
Kasimir Malewitsch, Sportler (1932)

„Und dein Missverständnis ist ganz natürlich. Wie kann eine Person, die immer auf einer Cocktailparty reist, die Gefühle und Eindrücke des Reisens mit dem Express oder dem Fliegen in der Luft verstehen? "





Kasimir Malewitsch (1916)





/ SQL. . , , ? -, ?





, 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. :





  1. ( , , http://localhost:52773/csp/sys/UtilHome.csp), 





  2. USER - Namespace %SYS   Switch USER





  3. > SQL - , SQL .





  4. " " "" - .





SQL .





, , , SQL IRIS, Visual Studio Code SQLTools "SQLTools Driver for InterSystems IRIS". .





IRIS ObjectScript VSCode.





SQLZoo





World:





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.





! , SQLZoo . . . .





— ,   "" 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







, , SQL ,  . , , . IRIS — .





, , IRIS WORLDPKey2 / :





set countryInfo = ##class(User.world).WORLDPKey2Open("France")







:





write countryInfo.name







write countryInfo.population







SQL . , , 100%.





, 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 . 





REST- IRIS.





- IRIS http://localhost:52773 /world/ /world/France. 





-:





http://localhost:52773/world/France





IRIS . , REST API OpenAPI 2.0. 





— API . REST-, IRIS:





  1. - URL, %CSP.REST





  2. - - IRIS





1 -





. "" REST: https://docs.intersystems.com/irislatest/csp/docbook/Doc.View.cls?KEY=GREST_csprest#GREST_csprest_urlmap





/// 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 .





: GraphQL InterSystems





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  









SELECT population 







  FROM world 







 WHERE name = 'France'











40  





,





set countryInfo = ##class(User.world).WhereName("France")







REST





20  









http://localhost:52773/world/France







GraphQL





5  









{ User_world ( name: France ) {







    name







    population







  }















  1. SQL, REST , , GraphQL . IRIS , , .





  2. , API XML (SOAP) JSON IRIS . .





  3. , API — , . , API , , .











,





Dieser Artikel wurde nicht nur zum Vergleich moderner APIs erstellt, sondern auch nicht so sehr für einen Überblick über die grundlegenden Funktionen von IRIS. Anfänger können die obigen Beispiele besser nutzen: Sehen Sie, wie einfach der Wechsel zwischen APIs beim Zugriff auf eine Datenbank ist, führen Sie die ersten Schritte in IRIS aus und erhalten Sie ein schnelles Ergebnis für ihre Aufgabe.





Daher ist Ihre Meinung sehr interessant. Hilft dieser Ansatz für einen "einfachen Start". Welche Schritte des Prozesses erschweren es Anfängern, die Werkzeuge für die Arbeit mit der API in IRIS zu beherrschen? Was schien ein "nicht offensichtliches Hindernis" zu sein? Fragen Sie diejenigen, die IRIS beherrschen, und schreiben Sie mir in den Kommentaren. Ich denke, es wird für alle nützlich sein, darüber zu diskutieren.








All Articles