Category: orientdb

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

    OrientDB – Create Property



    Property in OrientDB works like a field of class and column in the database table. Create Property is a command used to create a property for a particular class. The class name that you used in the command must exist.

    The following statement is the basic syntax of Create Property command.

    CREATE PROPERTY <class-name>.<property-name> <property-type> [<linked-type>][ <linked-class>]
    

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

    <class-name> − Defines the class you want to create the property in.

    <property-name> − Defines the logical name of the property.

    <property-type> − Defines the type of property you want to create.

    <linked-type> − Defines the container type, used in container property type.

    <linked-class> − Defines the container class, used in container property type.

    The following table provides the data type for property so that OrientDB knows the type of data to store.

    BOOLEAN INTEGER SHORT LONG
    FLOAT DATE STRING EMBEDDED
    LINK BYTE BINARY DOUBLE

    In addition to these there are several other property types that work as containers.

    EMBEDDEDLIST EMBEDDEDSET EMBEDDEDMAP
    LINKLIST LINKSET LINKMAP

    Example

    Try the following example to create a property name on the class Employee, of the String type.

    orientdb> CREATE PROPERTY Employee.name STRING
    

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

    Property created successfully with id = 1
    

    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 – Alter Cluster nhận dự án làm có lương

    OrientDB – Alter Cluster



    Alter Cluster command is to update attributes on an existing cluster. In this chapter you can learn how to add or modify the attributes of a cluster.

    The following statement is the basic syntax of Alter Cluster command.

    ALTER CLUSTER <cluster> <attribute-name> <attribute-value>
    

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

    <cluster> − Defines the cluster name.

    <attribute-name> − Defines the attribute you want to change.

    <attribute-value> − Defines the value you want to set for this attribute.

    The following tabular format provides the list of supported attributes you can use along with Alter cluster command.

    Name Type Description
    NAME String Changes the cluster name.
    STATUS String Changes the cluster status. Allowed values are ONLINE and OFFLINE. By default, clusters are online.
    COMPRESSION String Defines the compression type to use. Allowed values are NOTHING, SNAPPY, GZIP, and any other compression types registered in the OCompressionFactory class.
    USE_WAL Boolean Defines whether it uses the Journal when OrientDB operates against the cluster
    RECORD_GROW_FACTO R Integer Defines the grow factor to save more space on record creation. You may find this useful when you update the record with additional information.
    RECORD_OVERFLOW_GR OW_FACTOR Integer Defines grow factor on updates. When it reaches the size limit, is uses this setting to get more space, (factor > 1).
    CONFLICTSTRATEGY String Defines the strategy it uses to handle conflicts in the event that OrientDB MVCC finds an update or a delete operation it executes against an old record.

    The following table provides the list of Conflict strategies.

    Sr.No. Strategy & Description
    1

    Version

    Throws an exception when versions are different. This is the default setting.

    2

    Content

    In the event that the versions are different, it checks for changes in the content, otherwise it uses the highest version to avoid throwing an exception.

    3

    Automerge

    Merges the changes.

    Example

    Try the following example queries to learn Alter cluster command.

    Execute the following command to change the name of a cluster from Employee to Employee2.

    orientdb {db = demo}> ALTER CLUSTER Employee NAME Employee2
    

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

    Cluster updated successfully
    

    Execute the following command to change the name of a cluster from Employee2 to Employee using cluster ID.

    orientdb {db = demo}> ALTER CLUSTER 12 NAME Employee
    

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

    Cluster updated successfully
    

    Execute the following command to change the cluster conflict strategy to automerge.

    orientdb {db = demo}> ALTER CLUSTER V CONFICTSTRATEGY automerge
    

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

    Cluster updated successfully
    

    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 – Drop Cluster nhận dự án làm có lương

    OrientDB – Drop Cluster



    The Drop Cluster command removes the cluster and all its related content. This operation is permanent and rollback.

    The following statement is the basic syntax of Drop Cluster command.

    DROP CLUSTER <cluster-name>|<cluster-id>
    

    Where <cluster-name> defines the name of the cluster you want to remove and <cluster-id> defines the ID of the cluster you want to remove.

    Example

    Try the following command to remove Sales cluster.

    orientdb> DROP CLUSTER Sales
    

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

    Cluster dropped successfully
    

    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 Cluster nhận dự án làm có lương

    OrientDB – Truncate Cluster



    The Truncate Cluster command deletes all records of a cluster.

    The following statement is the basic syntax of Truncate Cluster Command.

    TRUNCATE CLUSTER <cluster-name>
    

    Where <cluster-name> is the name of the cluster.

    Example

    Try the following query to truncate the cluster named sales.

    Orientdb {db = demo}> TRUNCATE CLUSTER Profile
    

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

    Cluster truncated successfully.
    

    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 – Create Cluster nhận dự án làm có lương

    OrientDB – Create Cluster



    Cluster is an important concept in OrientDB which is used to store records, documents, or vertices. In simple words, cluster is a place where a group of records are stored. By default, OrientDB will create one cluster per class. All the records of a class are stored in the same cluster, which has the same name as the class. You can create up to 32,767(2^15-1) clusters in a database.

    The CREATE class is a command used to create a cluster with a specific name. Once the cluster is created, you can use the cluster to save records by specifying the name during the creation of any data model. If you want to add a new cluster to a class, use Alter Class command and ADDCLUSTER command.

    The following statement is the basic syntax of Create Cluster command.

    CREATE CLUSTER <cluster> [ID <cluster-id>]
    

    Where <cluster> defines the name of the cluster you want to create and <cluster-id> defines the numeric ID you want to use for the cluster.

    The following table provides the list of Cluster selection strategies.

    Sr.No. Strategy & Description
    1

    Default

    Selects the cluster using the class property default ClusterId.

    2

    Round-robin

    Selects the next cluster in a circular order. It is restarting once complete.

    3

    Balanced

    Selects the smallest cluster. Allows the class to have all underlying clusters balanced on size. When adding a new cluster to an existing class, it fills the new cluster first.

    Example

    Let us take an example to create a cluster named sales.

    orientdb> CREATE CLUSTER sales
    

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

    Cluster created correctly with id #12
    

    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 – Alter Property nhận dự án làm có lương

    OrientDB – Alter Property



    Alter Property is a command used to modify or update the Property of a particular class. Altering the property means modifying the fields of a table. In this chapter, you can learn how to update the property.

    The following statement is the basic syntax of Alter Property Command.

    ALTER PROPERTY <class>.<property> <attribute-name> <attribute-value>
    

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

    <class> − Defines the class to which the property belongs.

    <property> − Defines the property you want to update.

    <attribute-name> − Defines the attribute of a property you want to update.

    <attribute-value> − Defines the value you want to set on the attribute.

    The following table defines the list of attributes to alter the property.

    Attribute Type Description
    LINKEDCLASS String Defines the linked class name. Use NULL to remove an existing value.
    LINKEDTYPE String Defines the link type. Use NULL to remove an existing value.
    MIN Integer Defines the minimum value as a constraint. Use NULL to remove an existing constraint.
    MANDATORY Boolean Defines whether the property requires a value.
    MAX Integer Defines the maximum value as a constraint. Use NULL to remove an existing constraint.
    NAME String Defines the property name.
    NOTNULL Boolean Defines whether the property can have a NULL value.
    REGEX String Defines a Regular Expression as constraint. Use NULL to remove an existing constraint.
    TYPE String Defines a property type.
    COLLATE String Sets collate to one of the defined comparison strategies. By default, it is set to case-sensitive (cs). You can also set it to case-insensitive (ci).
    READONLY Boolean Defines whether the property value is immutable. That is, if it is possible to change it after the first assignment. Use with DEFAULT to have immutable values on creation.
    CUSTOM String Defines custom properties. The syntax for custom properties is <custom-name> = <custom-value>, such as stereotype = icon.
    DEFAULT   Defines the default value or function.

    Note − if you are altering NAME or TYPE, this command will take some time to update depending on the amount of data.

    Example

    Try some queries which are given below to understand Alter property.

    Execute the following query to change the name of the property from ‘age’ to ‘born’ in the class Customer.

    orinetdb {db = demo}> ALTER PROPERTY Customer.age NAME born
    

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

    Property altered successfully
    

    Execute the following query to make ‘name’ as the mandatory property of the class ‘Customer’.

    orientdb {db = demo}> ALTER PROPERTY Customer.name MANDATORY TRUE
    

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

    Property altered successfully
    

    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 – 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 – 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