Author: alien

  • Khóa học miễn phí OrientDB – Create Class nhận dự án làm có lương

    OrientDB – Create Class



    OrientDB supports multi-model feature and provides different ways in approaching and understanding the basic concepts of a database. However, we can easily access these models from the perspective of Document database API. Like RDBMS, OrientDB also uses the Record as an element of storage but it uses the Document type. Documents are stored in the form of Key/Value pairs. We are storing fields and properties as key/value pairs which belong to a concepts class.

    Class is a type of data model and the concept is drawn from the Object-oriented programming paradigm. Based on the traditional document database model, data is stored in the form of collection, while in the relational database model data it is stored in tables. OrientDB follows the Document API along with OPPS paradigm. As a concept, class in OrientDB has the closest relationship with the table in relational databases, but (unlike tables) classes can be schema-less, schema-full or mixed. Classes can inherit from other classes, creating trees of classes. Each class has its own cluster or clusters, (created by default, if none are defined).

    The following statement is the basic syntax of the Create Class Command.

    CREATE CLASS <class>
    [EXTENDS <super-class>]
    [CLUSTER <cluster-id>*]
    [CLUSTERS <total-cluster-number>]
    [ABSTRACT]
    

    Following are the details about the options in the above syntax.

    <class> − Defines the name of the class you want to create.

    <super-class> − Defines the super-class you want to extend with this class.

    <total-cluster-number> − Defines the total number of clusters used in this class. Default is 1.

    ABSTARCT − Defines the class is abstract. This is optional.

    Example

    As discussed, class is a concept related to table. Therefore here we will create a table Account. However, while creating class we cannot define fields i.e., properties based on OOPS paradigm.

    The following command is to create a class named Account.

    orientdb> CREATE CLASS Account
    

    If the above command is executed successfully, you will get the following output.

    Class created successfully
    

    You can use the following command to create a class Car which extends to class Vehicle.

    orientdb> CREATE CLASS Car EXTENDS Vehicle
    

    If the above command is executed successfully, you will get the following output.

    Class created successfully
    

    You can use the following command to create a class Person as abstract.

    orientdb> CREATE CLASS Person ABSTRACT
    

    If the above command is executed successfully, you will get the following output.

    Class created successfully
    

    Note − Without having properties, the class is useless and unable to build real object. In the further chapters, you can learn how to create properties for a particular class.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Delete Record nhận dự án làm có lương

    OrientDB – Delete Record



    Delete Record command is used to delete one or more records completely from the database.

    The following statement is the basic syntax of the Delete command.

    DELETE FROM <Class>|cluster:<cluster>|index:<index>
       [LOCK <default|record>]
       [RETURN <returning>]
       [WHERE <Condition>*]
       [LIMIT <MaxRecords>]
       [TIMEOUT <timeout>]
    

    Following are the details about the options in the above syntax.

    LOCK − Specifies how to lock the records between load and update. We have two options to specify Default and Record.

    RETURN − Specifies an expression to return instead of the number of records.

    LIMIT − Defines the maximum number of records to update.

    TIMEOUT − Defines the time you want to allow the update run before it times out.

    Note − Don’t use DELETE to remove Vertices or Edges because it effects the integrity of the graph.

    Example

    Let us consider the Customer table.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21

    Try the following query to delete the record having id = 4.

    orientdb {db = demo}> DELETE FROM Customer WHERE id = 4
    

    If the above query is executed successfully, you will get the following output.

    Delete 1 record(s) in 0.008000 sec(s).
    

    To check the record of Customer table you can use the following query.

    Orientdb {db = demo}> SELECT FROM Customer
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:1|Customer|2   |krishna|26
    2   |#11:2|Customer|3   |kiran  |29
    ----+-----+--------+----+-------+----
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Update Record nhận dự án làm có lương

    OrientDB – Update Record



    Update Record command is used to modify the value of a particular record. SET is the basic command to update a particular field value.

    The following statement is the basic syntax of the Update command.

    UPDATE <class>|cluster:<cluster>|<recordID>
       [SET|INCREMENT|ADD|REMOVE|PUT <field-name> = <field-value>[,]*] |[CONTENT| MERGE <JSON>]
       [UPSERT]
       [RETURN <returning> [<returning-expression>]]
       [WHERE <conditions>]
       [LOCK default|record]
       [LIMIT <max-records>] [TIMEOUT <timeout>]
    

    Following are the details about the options in the above syntax.

    SET − Defines the field to update.

    INCREMENT − Increments the specified field value by the given value.

    ADD − Adds the new item in the collection fields.

    REMOVE − Removes an item from the collection field.

    PUT − Puts an entry into map field.

    CONTENT − Replaces the record content with JSON document content.

    MERGE − Merges the record content with a JSON document.

    LOCK − Specifies how to lock the records between load and update. We have two options to specify Default and Record.

    UPSERT − Updates a record if it exists or inserts a new record if it doesn’t. It helps in executing a single query in the place of executing two queries.

    RETURN − Specifies an expression to return instead of the number of records.

    LIMIT − Defines the maximum number of records to update.

    TIMEOUT − Defines the time you want to allow the update run before it times out.

    Example

    Let us consider the same Customer table that we have used in the previous chapter.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 29

    Try the following query to update the age of a customer ‘Raja’.

    Orientdb {db = demo}> UPDATE Customer SET age = 28 WHERE name = ''Raja''
    

    If the above query is executed successfully, you will get the following output.

    Updated 1 record(s) in 0.008000 sec(s).
    

    To check the record of Customer table you can use the following query.

    orientdb {db = demo}> SELECT FROM Customer
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:1|Customer|2   |krishna|26
    2   |#11:2|Customer|3   |kiran  |29
    3   |#11:3|Customer|4   |javeed |21
    4   |#11:4|Customer|5   |raja   |28
    ----+-----+--------+----+-------+----
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Truncate Record nhận dự án làm có lương

    OrientDB – Truncate Record



    Truncate Record command is used to delete the values of a particular record.

    The following statement is the basic syntax of the Truncate command.

    TRUNCATE RECORD <rid>*
    

    Where <rid>* indicates the Record ID to truncate. You can use multiple Rids separated by comma to truncate multiple records. It returns the number of records truncated.

    Example

    Let us consider the same Customer table that we have used in the previous chapter.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 28

    Try the following query to truncate the record having Record ID #11:4.

    Orientdb {db = demo}> TRUNCATE RECORD #11:4
    

    If the above query is executed successfully, you will get the following output.

    Truncated 1 record(s) in 0.008000 sec(s).
    

    To check the record of Customer table you can use the following query.

    Orientdb {db = demo}> SELECT FROM Customer
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:1|Customer|2   |krishna|26
    2   |#11:2|Customer|3   |kiran  |29
    3   |#11:3|Customer|4   |javeed |21
    ----+-----+--------+----+-------+----
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Reload Record nhận dự án làm có lương

    OrientDB – Reload Record



    Reload Record also works similar to Load Record command and is also used to load a particular record from the schema. Load record will load the record with the help of Record ID. It is represented with @rid symbol in the result-set. The main difference is Reload record ignores the cache which is useful when external concurrent transactions is applied to change the record. It will give the latest update.

    The following statement is the basic syntax of the RELOAD Record command.

    RELOAD RECORD <record-id>
    

    Where <record-id> defines the record id of the record you want to reload.

    If you don’t know the Record ID of a particular record, then you can execute any query against the table. In the result-set you will find the Record ID (@rid) of the respective record.

    Example

    Let us consider the same Customer table that we have used in the previous chapter.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 29

    Try the following query to retrieve the record having Record ID @rid: #11:0.

    orientdb {db = demo}> LOAD RECORD #11:0
    

    If the above query is executed successfully, you will get the following output.

    +---------------------------------------------------------------------------+
    | Document - @class: Customer        @rid: #11:0           @version: 1      |
    +---------------------------------------------------------------------------+
    |                     Name | Value                                          |
    +---------------------------------------------------------------------------+
    |                       id | 1                                              |
    |                     name | satish                                         |
    |                      age | 25                                             |
    +---------------------------------------------------------------------------+
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Load Record nhận dự án làm có lương

    OrientDB – Load Record



    Load Record is used to load a particular record from the schema. Load record will load the record with the help of Record ID. It is represented with @rid symbol in the resultset.

    The following statement is the basic syntax of the LOAD Record command.

    LOAD RECORD <record-id>
    

    Where <record-id> defines the record id of the record you want to load.

    If you don’t know the Record ID of a particular record, then you can execute any query against the table. In the result-set you will find the Record ID (@rid) of the respective record.

    Example

    Let us consider the same Customer table that we have used in previous chapters.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 29

    Try the following query to retrieve the record having Record ID @rid: #11:0.

    orientdb {db = demo}> LOAD RECORD #11:0
    

    If the above query is executed successfully, you will get the following output.

    +---------------------------------------------------------------------------+
    | Document - @class: Customer        @rid: #11:0           @version: 1      |
    +---------------------------------------------------------------------------+
    |                     Name | Value                                          |
    +---------------------------------------------------------------------------+
    |                       id | 1                                              |
    |                     name | satish                                         |
    |                      age | 25                                             |
    +---------------------------------------------------------------------------+
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Export Record nhận dự án làm có lương

    OrientDB – Export Record



    Export Record is the command used to export the loaded record into the requested and supported format. If you are executing any wrong syntax, it will give the list of supported formats. OrientDB is a family of Document database, therefore JSON is the default supported format.

    The following statement is the basic syntax of the Export Record command.

    EXPORT RECORD <format>
    

    Where <Format> defines the format you want to get the record.

    Note − Export command will export the loaded record based on Record ID.

    Example

    Let us consider the same Customer table that we have used in the previous chapter.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 29

    Try the following query to retrieve the record having Record ID @rid: #11:0.

    orientdb {db = demo}> LOAD RECORD #11:0
    

    If the above query is executed successfully, you will get the following output.

    +---------------------------------------------------------------------------+
    | Document - @class: Customer        @rid: #11:0           @version: 1      |
    +---------------------------------------------------------------------------+
    |                     Name | Value                                          |
    +---------------------------------------------------------------------------+
    |                       id | 1                                              |
    |                     name | satish                                         |
    |                      age | 25                                             |
    +---------------------------------------------------------------------------+
    

    Use the following query to export he loaded record (#11:0) into JSON format.

    orientdb {db = demo}> EXPORT RECORD json
    

    If the above query is executed successfully, you will get the following output.

    {
       "@type": "d",
          "@rid": "#11:0",
       "@version": 1,
       "@class": "Customer",
          "id": 1,
          "name": "satish",
          "age": 25
    }
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Insert Record nhận dự án làm có lương

    OrientDB – Insert Record



    OrientDB is a NoSQL database that can store the documents and graph-oriented data. NoSQL database does not contain any table, so how can you insert data as a record. Here you can see the table data in the form of class, property, vertex, and edge meaning classes are like tables, and properties are like files in the tables.

    We can define all these entities using schema in OrientDB. Property data can be inserted into a class. Insert command creates a new record in the database schema. Records can be schema-less or follow some specified rules.

    The following statement is the basic syntax of the Insert Record command.

    INSERT INTO [class:]<class>|cluster:<cluster>|index:<index>
       [(<field>[,]*) VALUES (<expression>[,]*)[,]*]|
       [SET <field> = <expression>|<sub-command>[,]*]|
       [CONTENT {<JSON>}]
       [RETURN <expression>]
       [FROM <query>]
    

    Following are the details about the options in the above syntax.

    SET − Defines each field along with the value.

    CONTENT − Defines JSON data to set field values. This is optional.

    RETURN − Defines the expression to return instead of number of records inserted. The most common use cases are −

    • @rid − Returns the Record ID of the new record.

    • @this − Returns the entire new record.

    FROM − Where you want to insert the record or a result set.

    Example

    Let us consider a Customer table with the following fields and types.

    Sr.No. Field Name Type
    1 Id Integer
    2 Name String
    3 Age Integer

    You can create the Schema (table) by executing the following commands.

    CREATE DATABASE PLOCAL:/opt/orientdb/databases/sales
    CREATE CLASS Customer
    CREATE PROPERTY Customer.id integer
    CREATE PROPERTY Customer.name String
    CREATE PROPERTY Customer.age integer
    

    After executing all the commands, you will get the table name Customer with id, name, and age fields. You can check the table by executing select query into the Customer table.

    OrientDB provides different ways to insert a record. Consider the following Customer table containing the sample records.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 29

    The following command is to insert the first record into the Customer table.

    INSERT INTO Customer (id, name, age) VALUES (01,''satish'', 25)
    

    If the above command is successfully executed, you will get the following output.

    Inserted record ''Customer#11:0{id:1,name:satish,age:25} v1'' in 0.069000 sec(s).
    

    The following command is to insert the second record into the Customer table.

    INSERT INTO Customer SET id = 02, name = ''krishna'', age = 26
    

    If the above command is successfully executed, you will get the following output.

    Inserted record ''Customer#11:1{id:2,age:26,name:krishna} v1'' in 0.005000 sec(s).
    

    The following command is to insert the third record into the Customer table.

    INSERT INTO Customer CONTENT {"id": "03", "name": "kiran", "age": "29"}
    

    If the above command is successfully executed, you will get the following output.

    Inserted record ''Customer#11:2{id:3,name:kiran,age:29} v1'' in 0.004000 sec(s).
    

    The following command is to insert the next two records into the Customer table.

    INSERT INTO Customer (id, name, age) VALUES (04,''javeed'', 21), (05,''raja'', 29)
    

    If the above command is successfully executed, you will get the following output.

    Inserted record ''[Customer#11:3{id:4,name:javeed,age:21} v1,
    Customer#11:4{id:5,name:raja,age:29} v1]'' in 0.007000 sec(s).
    

    You can check if all these records are inserted or not by executing the following command.

    SELECT FROM Customer
    

    If the above command is successfully executed, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:1|Customer|2   |krishna|26
    2   |#11:2|Customer|3   |kiran  |29
    3   |#11:3|Customer|4   |javeed |21
    4   |#11:4|Customer|5   |raja   |29
    ----+-----+--------+----+-------+----
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Display Records nhận dự án làm có lương

    OrientDB – Display Records



    Similar to RDBMS, OrientDB supports different types of SQL queries to retrieve the records from the database. While retrieving the records we have different variations or options of queries along with the select statement.

    The following statement is the basic syntax of the SELECT command.

    SELECT [ <Projections> ] [ FROM <Target> [ LET <Assignment>* ] ]
       [ WHERE <Condition>* ]
       [ GROUP BY <Field>* ]
       [ ORDER BY <Fields>* [ ASC|DESC ] * ]
       [ UNWIND <Field>* ]
       [ SKIP <SkipRecords> ]
       [ LIMIT <MaxRecords> ]
       [ FETCHPLAN <FetchPlan> ]
       [ TIMEOUT <Timeout> [ <STRATEGY> ] ]
       [ LOCK default|record ]
       [ PARALLEL ]
       [ NOCACHE ]
    

    Following are the details about the options in the above syntax.

    <Projections> − Indicates the data you want to extract from the query as a result records set.

    FROM − Indicates the object to query. This can be a class, cluster, single Record ID, set of Record IDs. You can specify all these objects as target.

    WHERE − Specifies the condition to filter the result-set.

    LET − Indicates the context variable which are used in projections, conditions or sub queries.

    GROUP BY − Indicates the field to group the records.

    ORDER BY − Indicates the filed to arrange a record in order.

    UNWIND − Designates the field on which to unwind the collection of records.

    SKIP − Defines the number of records you want to skip from the start of the result-set.

    LIMIT − Indicates the maximum number of records in the result-set.

    FETCHPLAN − Specifies the strategy defining how you want to fetch results.

    TIMEOUT − Defines the maximum time in milliseconds for the query.

    LOCK − Defines the locking strategy. DEFAULT and RECORD are the available lock strategies.

    PARALLEL − Executes the query against ‘x’ concurrent threads.

    NOCACHE − Defines whether you want to use cache or not.

    Example

    Let’s consider the following Customer table created in the previous chapter.

    Sr.No. Name Age
    1 Satish 25
    2 Krishna 26
    3 Kiran 29
    4 Javeed 21
    5 Raja 29

    Try different select queries to retrieve the data records from the Customer table.

    Method 1 − You can use the following query to select all records from the Customer table.

    orientdb {db = demo}> SELECT FROM Customer
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:1|Customer|2   |krishna|26
    2   |#11:2|Customer|3   |kiran  |29
    3   |#11:3|Customer|4   |javeed |21
    4   |#11:4|Customer|5   |raja   |29
    ----+-----+--------+----+-------+----
    

    Method 2 − Select all records whose name starts with the letter ”k”.

    orientdb {db = demo}> SELECT FROM Customer WHERE name LIKE ''k%''
    

    OR you can use the following query for the above example.

    orientdb {db = demo}> SELECT FROM Customer WHERE name.left(1) = ''k''
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:1|Customer|2   |krishna|26
    1   |#11:2|Customer|3   |kiran  |29
    ----+-----+--------+----+-------+----
    

    Method 3 − Select id, name records from the Customer table with names in uppercase letters.

    orientdb {db = demo}> SELECT id, name.toUpperCase() FROM Customer
    

    If the above query is executed successfully, you will get the following output.

    ----+--------+----+-------
    #   |@CLASS  |id  |name
    ----+--------+----+-------
    0   |null    |1   |SATISH
    1   |null    |2   |KRISHNA
    2   |null    |3   |KIRAN
    3   |null    |4   |JAVEED
    4   |null    |5   |RAJA
    ----+--------+----+-------
    

    Method 4 − Select all records from the Customer table where age is in the range of 25 to 29.

    orientdb {db = demo}> SELECT FROM Customer WHERE age in [25,29]
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:2|Customer|3   |kiran  |29
    2   |#11:4|Customer|5   |raja   |29
    ----+-----+--------+----+-------+----
    

    Method 5 − Select all records from the Customer table where any field contains the word ‘sh’.

    orientdb {db = demo}> SELECT FROM Customer WHERE ANY() LIKE ''%sh%''
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:0|Customer|1   |satish |25
    1   |#11:1|Customer|2   |krishna|26
    ----+-----+--------+----+-------+----
    

    Method 6 − Select all records from the Customer table, ordered by age in descending order.

    orientdb {db = demo}> SELECT FROM Customer ORDER BY age DESC
    

    If the above query is executed successfully, you will get the following output.

    ----+-----+--------+----+-------+----
    #   |@RID |@CLASS  |id  |name   |age
    ----+-----+--------+----+-------+----
    0   |#11:2|Customer|3   |kiran  |29
    1   |#11:4|Customer|5   |raja   |29
    2   |#11:1|Customer|2   |krishna|26
    3   |#11:0|Customer|1   |satish |25
    4   |#11:3|Customer|4   |javeed |21
    ----+-----+--------+----+-------+----
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Optimize Database nhận dự án làm có lương

    OrientDB – Optimize Database



    As per technical terminology Optimization means “Achieve the better possible performance in the quickest amount of time.” With reference to database, optimization involves maximizing the speed and efficiency with which data is retrieved.

    OrientDB supports lightweight edges, which means a direct relation between the data entities. In simple terms, it is a field-to-field relation. OrientDB provides different ways to optimize the database. It supports the conversion of regular edges to lightweight edges.

    The following statement is the basic syntax of the Optimize database command.

    OPTMIZE DATABASE [-lwedges] [-noverbose]
    

    Where lwedges converts regular edges into lightweight edges and noverbose disables the output.

    Example

    In this example, we will use the same database named ‘demo’ that we created in the previous chapter. You can use the following optimize database command.

    OPTIMIZE DATABASE -lwedges
    

    If it is successfully executed, you will get some successful notifications along with the completion message.

    Database Optimization completed in 35ms
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc