results matching ""
No results matching ""
1.5.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()
¶ 1.5.1. 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
});
¶ 1.5.2. _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.
¶ 1.5.3. Get()
Read and query data. The returned result contains the following four objects:
- sum, is the total number of records in the database.
- data, is a array of returned records.
- go, is the index of current record.
- max, is the maximum number of returned records.
¶ 1.5.4. ID()
ID() is an overloaded function of Get().
ID(id) = Get{_id:id}
So just return the data of the id.
¶ 1.5.5. Set()
Update data.
¶ 1.5.6. Mix()
Merge data, instead of Put.
¶ 1.5.7. 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
{ <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.
小礼物刷一波,打赏作者

Paypal Donate

Venmo Donate

WeChat微信打赏

Alipay支付宝打赏