Author: alien

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

    OrientDB – Delete Vertex



    Delete Vertex command is used to remove vertices from the database. While deleting, it checks and maintains the consistency with the edges and removes all cross-references (with the edges) to the deleted vertex.

    The following statement is the basic syntax of Delete Vertex Command.

    DELETE VERTEX <vertex> [WHERE <conditions>]
    [LIMIT <MaxRecords>>] [BATCH <batch-size>]
    

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

    <vertex> − Defines the vertex that you want to remove, using its Class, Record ID, or through a sub-query.

    WHERE − Filters condition to determine which records the command removes.

    LIMIT − Defines the maximum number of records to be removed.

    BATCH − Defines how many records the command removes at a time, allowing you to break large transactions into smaller blocks to save on memory usage.

    Example

    Try the following command to learn how to delete single vertex or multiple vertices.

    Execute the following command to remove the vertex ‘#14:1’.

    orientdb> DELETE VERTEX #14:1
    

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

    Delete record(s) ''1'' in 0.005000 sec(s)
    

    Execute the following command to remove all vertices from the class ‘Customer’ marked with the property ‘isSpam’.

    orientdb> DELETE VERTEX Customer WHERE isSpam = TRUE
    

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

    Delete record(s) ''3'' in 0.005000 sec(s)
    

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