Category: orientdb

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

    OrientDB – Alter Class



    Class and Property in OrientDB are used to build a schema with the respective attributes such as class name, super-class, cluster, number of clusters, Abstract, etc. If you want to modify or update any attribute of existing classes in the schema then you have to use Alter Class command.

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

    ALTER CLASS <class> <attribute-name> <attribute-value>
    

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

    <class> − Defines the class name.

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

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

    The following table defines the list of attributes that support Alter Class command.

    Attribute Type Description
    NAME String Changes the class name.
    SHORTNAME String Defines a short name, (that is, an alias), for the class. Use NULL to remove a short name assignment.
    SUPERCLASS String Defines a super-class for the class. To add a new class, you can use the syntax +<class>, to remove it use -<class>.
    OVERSIZE Decimal number Defines the oversize factor.
    ADDCLUSTER String Adds a cluster to the class. If the cluster doesn”t exist, it creates a physical cluster. Adding clusters to a class is also useful in storing records in distributed servers.
    REMOVECLUSTER String Removes a cluster from a class. It does not delete the cluster, only removes it from the class.
    STRICTMODE Enables or disables strict mode. When in strict mode, you work in schema-full mode and cannot add new properties to a record if they are part of the class” schema definition.
    CLUSTERSELECTION Defines the selection strategy in choosing which cluster it uses for new records.
    CUSTOM Defines custom properties. Property names and values must follow the syntax <propertyname>=<value> without spaces between the name and value.
    ABSTRACT Boolean Converts class to an abstract class or the opposite.

    Example

    Let us try few examples that will update or modify the attributes of the existing class.

    The following query is used to define a super-class ‘Person’ for an existing class ‘Employee’.

    orientdb> ALTER CLASS Employee SUPERCLASS Person
    

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

    Class altered successfully
    

    The following query is used to add a super-class ‘Person’ for an existing class ‘Employee’.

    orientdb> ALTER CLASS Employee SUPERCLASS +Person
    

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

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

    OrientDB – Truncate Class



    Truncate class will delete all records of clusters defined as part of class. In OrientDB, every class has an associated cluster with the same name. If you want to also remove all records from the class hierarchy, you need to use the POLYMORPHIC keyword.

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

    TRUNCATE CLASS <class> [ POLYMORPHIC ] [ UNSAFE ]
    

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

    <class> − Defines the class you want to truncate.

    POLYMORPHIC − Defines whether the command also truncates the hierarchy.

    UNSAFE − Defines the command forces truncation on vertex or edge class.

    Example

    The following query to truncate a class Profile.

    orientdb> TRUNCATE CLASS Profile
    

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

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

    OrientDB – Drop Class



    The Drop Class command removes a class from the schema. It is important to pay attention and maintain a consistent schema. For example, avoid to remove classes that are super-classes of others. The associated cluster won”t be deleted.

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

    DROP CLASS <class>
    

    Drop a class with the class name.

    Example

    Try the following query to Drop a class Employee.

    Orientdb> DROP CLASS Employee
    

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

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