Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mg-dbx

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mg-dbx - npm Package Compare versions

Comparing version 1.1.5 to 1.2.6

src/mg-class.cpp

2

package.json

@@ -5,3 +5,3 @@ {

"description": "High speed Synchronous and Asynchronous access to M-like databases from Node.js.",
"version": "1.1.5",
"version": "1.2.6",
"maintainers": "Chris Munt <cmunt@mgateway.com>",

@@ -8,0 +8,0 @@ "homepage": "https://github.com/chrisemunt/mg-dbx",

@@ -6,3 +6,3 @@ # mg-dbx

Chris Munt <cmunt@mgateway.com>
4 October 2019, M/Gateway Developments Ltd [http://www.mgateway.com](http://www.mgateway.com)
10 October 2019, M/Gateway Developments Ltd [http://www.mgateway.com](http://www.mgateway.com)

@@ -113,2 +113,20 @@ * Verified to work with Node.js v4 to v12.

#### Returning (and optionally changing) the current directory (or Namespace)
current_namespace = db.namespace([<new_namespace>]);
Example 1 (Get the current Namespace):
var nspace = db.namespace();
* Note this will return the current Namespace for InterSystems databases and the value of the current global directory for YottaDB (i.e. $ZG).
Example 2 (Change the current Namespace):
var new_nspace = db.namespace("SAMPLES");
* If the operation is successful this method will echo back the new Namespace name. If not successful, the method will return the name of the current (unchanged) Namespace.
### Invocation of database commands

@@ -118,3 +136,3 @@

global := db.mglobal(<global_name>[, <fixed_key>])
global = db.mglobal(<global_name>[, <fixed_key>]);

@@ -219,2 +237,49 @@ Example (using a global named "Person"):

#### Increment the value of a global node
Synchronous:
var result = <global>.increment(<key>, <increment_value>);
Asynchronous:
<global>.increment(<key>, <increment_value>, callback(<error>, <result>));
Example (increment the value of the "counter" node by 1.5 and return the new value):
var result = person.increment("counter", 1.5);
#### Lock a global node
Synchronous:
var result = <global>.lock(<key>, <timeout>);
Asynchronous:
<global>.lock(<key>, <timeout>, callback(<error>, <result>));
Example (lock global node '1' with a timeout of 30 seconds):
var result = person.lock(1, 30);
* Note: Specify the timeout value as '-1' for no timeout (i.e. wait until the global node becomes available to lock).
#### Unlock a (previously locked) global node
Synchronous:
var result = <global>.unlock(<key>);
Asynchronous:
<global>.unlock(<key>, callback(<error>, <result>));
Example (unlock global node '1'):
var result = person.unlock(1);
#### Reset a global name (and fixed key)

@@ -234,2 +299,3 @@

### Cursor based data retrieval

@@ -248,3 +314,5 @@

* **multilevel**: A boolean value (default: **multilevel: false**). Set to 'true' to return all descendant nodes from the specified 'seed_key'.
* **getdata**: A boolean value (default: **getdata: false**). Set to 'true' to return any data values associated with each global node returned.
* **format**: Format for output (default: not specified). If the output consists of multiple data elements, the return value (by default) is a JavaScript object made up of a 'key' array and an associated 'data' value. Set to "url" to return such data as a single URL escaped string including all key values ('key[1->n]') and any associated 'data' value.

@@ -294,3 +362,3 @@

while ((result = query.next()) !== null) {
console.log("result: " + result);
console.log("result: " + JSON.stringify(result, null, '\t'));
}

@@ -301,2 +369,14 @@

#### Traversing the global directory (return a list of global names)
query = db.mglobalquery({global: <seed_global_name>}, {globaldirectory: true});
Example (return all global names held in the current directory)
query = db.mglobalquery({global: ""}, {globaldirectory: true});
while ((result = query.next()) !== null) {
console.log("result: " + result);
}
### Invocation of database functions

@@ -324,2 +404,77 @@

### Direct access to InterSystems classes (IRIS and Cache)
#### Invocation of a ClassMethod
Synchronous:
result = db.classmethod(<class_name>, <classmethod_name>, <parameters>);
Asynchronous:
db.function(<class_name>, <classmethod_name>, <parameters>, callback(<error>, <result>));
Example (Encode a date to internal storage format):
result = db.classmethod("%Library.Date", "DisplayToLogical", "10/10/2019");
#### Creating and manipulating instances of objects
The following simple class will be used to illustrate this facility.
Class User.Person Extends %Persistent
{
Property Number As %Integer;
Property Name As %String;
Property DateOfBirth As %Date;
Method Age(AtDate As %Integer) As %Integer
{
Quit (AtDate - ..DateOfBirth) \ 365.25
}
}
#### Create an entry for a new Person
person = db.classmethod("User.Person", "%New");
Add Data:
result = person.setproperty("Number", 1);
result = person.setproperty("Name", "John Smith");
result = person.setproperty("DateOfBirth", "12/8/1995");
Save the object record:
result = person.method("%Save");
#### Retrieve an entry for an existing Person
Retrieve data for object %Id of 1.
person = db.classmethod("User.Person", "%OpenId", 1);
Return properties:
var number = person.getproperty("Number");
var name = person.getproperty("Name");
var dob = person.getproperty("DateOfBirth");
Calculate person's age at a particular date:
today = db.classmethod("%Library.Date", "DisplayToLogical", "10/10/2019");
var age = person.method("Age", today);
#### Reusing an object container
Once created, it is possible to reuse containers holding previously instantiated objects using the **reset()** method. Using this technique helps to reduce memory usage in the Node.js environment.
Example 1 Reset a container to hold a new instance:
person.reset("User.Person", "%New");
Example 2 Reset a container to hold an existing instance (object %Id of 2):
person.reset("User.Person", "%OpenId", 2);
### Return the version of mg-dbx

@@ -368,4 +523,13 @@

* Introduce global 'increment()' and 'lock(); methods.
* Introduce cursor based data retrieval.
* Introduce outline support for multithreading in JavaScript - **currently not stable!**.
### v1.2.6 (10 October 2019)
* Introduce support for direct access to InterSystems IRIS/Cache classes.
* Extend cursor based data retrieval to include an option for generating a global directory listing.
* Introduce a method to report and (optionally change) the current working global directory (or Namespace).
* Correct a fault that led to the timeout occasionally not being honoured in the **lock()** method.
* Correct a fault that led to Node.js exceptions not being processed correctly.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc