Can globals exist without SQL access?
Hello everyone,
My team lead mentioned that users can sometimes create globals directly without associating them with tables or classes. In this case, these globals would not be accessible via SQL.
Is this correct? Can a global exist independently in this way, and if so, is there a specific approach to access or manage them without SQL?
Comments
Yes, globals can exist independently without any association with SQL tables or classes, and in such situations, they wouldn't be accessible via SQL. Globals are a unique storage structure in InterSystems IRIS, serving as persistent multidimensional sparse arrays. These can be directly manipulated with ObjectScript or other programming languages compatible with IRIS, allowing the creation of custom data structures not adhering to relational or object models. Without SQL integration or object class mapping, such globals are strictly managed at the global level [1][2].
Sources:
Just a small correction - Globals aren't unique to IRIS. There are other databases that use them out there. Search for M or Mumps databases to find out more.
Yes. You can use a variable name starting with ^, like ^MyGlobal, and it will be a global. You will not be able to access it via SQL, but you will be able to see it with the globals in the system management portal. You can also reference globals in a different namespace by using ^|"namespace"|MyGlobal.
Globals can be defined and accessed directly using a caret (^) symbol. For example, you can set or access a global with:
// define a global by setting a value
set ^GlobalName = "Hello World"
// Access different sub-nodes
set ^GlobalName(1, "foo") = "bar"
// You access the global in a similar way
write ^GlobalName // prints Hello World
// write all global values
zwrite ^GlobalName
// ^GlobalName = "Hello World"
// ^GlobalName(1,"foo") = "bar"This can be useful for quickly saving values globally or looking up values.
I recommend having a look at the Using Caché Globals section of the Cache documentation because it has far more information on globals usage than could be relayed in a comment.
They can exist without SQL access but you can always make them available through SQL at a later date by mapping a class to them.
and by "always" Tim means: "in some cases with a only little bit of work, but sometimes with a large amount of work"
Right, Tim?
True. And it depends on how logically the globals were set up in the first place as to whether the mapped tables/classes can reflect a sensible logical schema. You could still map them without that but it wouldn't be great for usability.
Yes, a global exists without SQL association. If you want to associate an SQL definition you should map it to SQL
See here to discover how standard Global storage (eg IRIS Globals) can be automatically abstracted as JavaScript/JSON objects from within Node.js or Bun.js (without the need for any supporting metadata):
https://github.com/robtweed/glsdb
For broader examples of how to use Global Storage with JavaScript, see: