CRUD Interface

CRUD Interface includes New, Get, Set, Mix,and Del. CRUD Interface is below the X method. therefore CRUD Interface must be used follow the X method. To manipulate, for instance, the Get of CRUD interface for a X method is as follow:

tim.X("test").Get()

New()

If the collection does not currently exist, insert operations will create the collection.

Create data and insert Documents. 'New' method must include an argument of JSON object. The following example inserts a new document into the test collection.

tim.X("test").New({name:"Tom Rot"})

If the documents do not specify an _id field, X-Server adds the _id field with an ObjectId value to each document.

More fields:

tim.X("test").New({
  name: "Jerry Cat",
  sex:"Boy",
  position:"Intern",
  age:20
});

_id Field

In X-Server, each document stored in a collection requires a unique _id field that acts as a primary key. If an inserted document omits the _id field, the X-Server automatically generates an ObjectId for the _id field.

Get()

Read and query data. The returned result contains the following four objects:

  1. sum, is the total number of records in the database.

  2. data, is a array of returned records.

  3. go, is the index of current record.

  4. max, is the maximum number of returned records.

ID()

ID() is an overloaded function of Get().

ID(id) = Get{_id:id}

So just return the data of the id.

Set()

Update data.

Mix()

Merge data, instead of Put.

Del()

To delete all documents from a collection, pass an empty filter document {} to the Del() method. The following example deletes all documents from the test collection:

tim.X("test").Del();

Delete All Documents that Match a Condition You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

To specify equality conditions, use : expressions in the query filter document:

{ <field1>: <value1>, ... }

A query filter document can use the query operators to specify conditions in the following form:

{ <field1>: { <operator1>: <value1> }, ... }

To delete all documents that match a deletion criteria, pass a filter parameter to the Del() method.

The following example removes all documents from the inventory collection where the status field equals "A":

tim.X("test").Del({ status : "A" })

To Be Continued

This page is just an unfinished draft. The author is writing now. Welcome to donate, cheer for the author.

Last updated