Ejemplo n.º 1
0
    def open_session():
        store = documentstore()
        store.initialize()

        # region store_entities_1
        def store(self, entity, key=None, etag=None, force_concurrency_check=False):
            # endregion
            pass

        with store.open_session() as session:
            entity = Employee("first_name", "second_name")
            etag = ""
            # region store_entities_2
            session.store(entity)
            # endregion

            # region store_entities_3
            session.store(entity, etag=etag)
            # endregion

            # region store_entities_4
            session.store(entity, key="doc/1")
            # endregion

            # region store_entities_5
            session.store(entity, key="doc/1", etag=etag)
            # endregion

        with store.open_session() as session:
            # region store_entities_6
            # generate Id automatically
            # # when we have a new and empty database and conventions are not changed: 'employees/1'
            employee = Employee("John", "Doe")
            session.store(employee)
            session.save_changes()
Ejemplo n.º 2
0
    def get_store():
        global store
        if not store:
            store = documentstore(url="http://localhost.fiddler:8080", database="demoDB")
            store.initialize()

        return store
Ejemplo n.º 3
0
    def open_session():
        store = documentstore()
        store.initialize()


        # region deleting_1
        def delete(self, key_or_entity):

        def delete_by_entity(self, entity):
        # endregion

        with store.open_session() as session:
            # region deleting_2
            employee = session.load("employees/1")
            session.delete(employee)
            session.save_changes()
            # endregion

        with store.open_session() as session:
            # region deleting_3
            session.delete("employees/1")
            # endregion


        with store.open_session() as session:
            # region deleting_4
            employee = session.load("employees/1")
            session.delete_by_entity(employee)
            # endregion
Ejemplo n.º 4
0
    def what_is_session():
        with documentstore() as store:
            store.initialize()
            # region session_usage_1

            with store.open_session() as session:
                entity = Company(name= "Company")
                session.store(entity)
                session.save_changes()
                company_id = entity.Id

            with store.open_session() as session:
                entity = session.load(company_id, object_type= Company)
                print(entity.name)

            # endregion

            # region session_usage_2

            with store.open_session() as session:
                entity = session.load(company_id, object_type=Company)
                entity.name = "Another Company"
                session.save_changes()

            # endregion

            with store.open_session() as session:
                # region session_usage_3
                TestCase.assertTrue(session.load(company_id, object_type=Company)
                                    is session.load(company_id, object_type=Company))
Ejemplo n.º 5
0
 def setUpClass(cls):
     super(TestQuery, cls).setUpClass()
     cls.index_map = ("from doc in docs "
                      "select new {"
                      "name = doc.name,"
                      "key = doc.key,"
                      "doc_id = (doc.name + \" \") + doc.key}")
     cls.index_sort = IndexDefinition(index_map=cls.index_map, sort_options={"key": SortOptions.float},
                                      stores={"doc_id": "Yes"})
     cls.db.put_index("Testing_Sort", index_def=cls.index_sort, overwrite=True)
     cls.db.put("products/101", {"name": "test101", "key": 2, "order": "a"},
                {"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
     cls.db.put("products/10", {"name": "test10", "key": 3, "order": "b"}, {})
     cls.db.put("products/106", {"name": "test106", "key": 4, "order": "c"}, {})
     cls.db.put("products/107", {"name": "test107", "key": 5, "order": None},
                {"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
     cls.db.put("products/103", {"name": "test107", "key": 6},
                {"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
     cls.db.put("products/108", {"name": "new_testing", "key": 90, "order": "d"},
                {"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
     cls.db.put("orders/105", {"name": "testing_order", "key": 92, "product": "products/108"},
                {"Raven-Entity-Name": "Orders"})
     cls.db.put("company/1",
                {"name": "withNesting", "product": {"name": "testing_order", "key": 4, "order": None}},
                {"Raven-Entity-Name": "Companies"})
     cls.db.put("specials/1", {"url": "https://ravendb.net/"})
     cls.db.put("specials/2",
                {"url": "http://www.example.com/ebx/LinkResolverServlet?classofcontent=Standard&id=63935",
                 "date": "2017.03.05T00:00:00.000"})
     cls.db.put("specials/3",
                {"wild_cards": "%~#+!$,;'*[]?*",
                 "date": "2017.03.05T00:00:01.000"})
     cls.document_store = documentstore(cls.default_url, cls.default_database)
     cls.document_store.initialize()
Ejemplo n.º 6
0
    def what_is_session():
        with documentstore() as store:
            store.initialize()
            # region session_usage_1

            with store.open_session() as session:
                entity = Company(name="Company")
                session.store(entity)
                session.save_changes()
                company_id = entity.Id

            with store.open_session() as session:
                entity = session.load(company_id, object_type=Company)
                print(entity.name)

            # endregion

            # region session_usage_2

            with store.open_session() as session:
                entity = session.load(company_id, object_type=Company)
                entity.name = "Another Company"
                session.save_changes()

            # endregion

            with store.open_session() as session:
                # region session_usage_3
                TestCase.assertTrue(
                    session.load(company_id, object_type=Company) is
                    session.load(company_id, object_type=Company))
Ejemplo n.º 7
0
    def replication_failover(document_id):
        with documentstore(url="http://localhost:8080", database="Rep1") as store:
            store.initialize()

            with store.open_session() as session:
                results = session.load(document_id)

                return results
 def setUpClass(cls):
     super(TestDelete, cls).setUpClass()
     cls.db.put("products/101", {"name": "test"}, {"Raven-Python-Type": "delete_test.Product"})
     cls.db.put("products/10", {"name": "test"}, {})
     cls.db.put("products/106", {"name": "test"}, {})
     cls.db.put("products/107", {"name": "test"}, {})
     cls.document_store = documentstore(cls.default_url, cls.default_database)
     cls.document_store.initialize()
Ejemplo n.º 9
0
    def get_store():
        global store
        if not store:
            store = documentstore(url="http://localhost.fiddler:8080",
                                  database="demoDB")
            store.initialize()

        return store
Ejemplo n.º 10
0
    def replication_failover(document_id):
        with documentstore(url="http://localhost:8080",
                           database="Rep1") as store:
            store.initialize()

            with store.open_session() as session:
                results = session.load(document_id)

                return results
Ejemplo n.º 11
0
 def setUpClass(cls):
     super(TestLoad, cls).setUpClass()
     cls.db.put("products/101", {"name": "test"},
                {"Raven-Python-Type": Product.__module__+".Product"})
     cls.db.put("products/10", {"name": "test"}, {})
     cls.db.put("orders/105", {"name": "testing_order", "key": 92, "product": "products/101"},
                {"Raven-Entity-Name": "Orders"})
     cls.db.put("company/1", {"name": "test", "product": {"name": "testing_nested"}}, {})
     cls.document_store = documentstore(cls.default_url, cls.default_database)
     cls.document_store.initialize()
Ejemplo n.º 12
0
    def setUpClass(cls):
        super(TestConversion, cls).setUpClass()

        cls.db.put("times/3",
                   {"td": Utils.timedelta_to_str(timedelta(days=20, minutes=23, seconds=59, milliseconds=254)),
                    "dt": Utils.datetime_to_string(datetime.now())}, {"Raven-Entity-Name": "Times"})

        cls.db.put("times/4",
                   {"td": Utils.timedelta_to_str(timedelta(minutes=23, seconds=59, milliseconds=254)),
                    "dt": Utils.datetime_to_string(datetime.now())}, {"Raven-Entity-Name": "Times"})

        cls.document_store = documentstore(cls.default_url, cls.default_database)
        cls.document_store.initialize()
 def setUpClass(cls):
     super(FullTextSearchTest, cls).setUpClass()
     cls.db.put("LastFms/1", {"artist": "Tania Maria", "track_id": "TRALPJJ128F9311763", "title": "Come With Me",
                              "datetime_time": datetime.now(), "tags": None},
                {"Raven-Entity-Name": "LastFms", "Raven-Python-Type": "full_text_search_test.LastFm"})
     cls.db.put("LastFms/2", {"artist": "Meghan Trainor", "track_id": "TRBCNGI128F42597B4", "title": "Me Too",
                              "datetime_time": datetime.now(), "tags": None},
                {"Raven-Entity-Name": "LastFms", "Raven-Python-Type": "full_text_search_test.LastFm"})
     cls.db.put("LastFms/3", {"artist": "Willie Bobo", "track_id": "TRAACNS128F14A2DF5", "title": "Spanish Grease",
                              "datetime_time": datetime.now(), "tags": None},
                {"Raven-Entity-Name": "LastFms", "Raven-Python-Type": "full_text_search_test.LastFm"})
     cls.document_store = documentstore(cls.default_url, cls.default_database)
     cls.document_store.initialize()
     LastFmAnalyzed().execute(cls.document_store)
Ejemplo n.º 14
0
    def saving_changes():
        store = documentstore()
        store.initialize()

        # region saving_changes_1
        def save_changes(self):
            # endregion
            pass

        with store.open_session() as session:
            # region saving_changes_2
            # storing new entity
            session.store(Employee("first_name", "second_name"))

            session.save_changes()
            # endregion
Ejemplo n.º 15
0
    def open_session():
        store = documentstore()
        store.initialize()

        # region open_session_1
        # Open session for a 'default' database configured in 'documentstore'
        with store.open_session() as session:
            session.load("doc/1")
            # code here

        # Open session for a specific database
        with store.open_session(database="Your database") as session:
            session.load("doc/2")
            # code here

        # Open session for a specific database with api_key
        with store.open_session(database="Your database", api_key="API_KEY") as session:
            session.load("doc/3")
    def sample(self):
        try:
            document_store = documentstore()
            # region client_integration_1
            document_store.conventions.failover_behavior = Failover.fail_immediately
            # endregion

            # region client_integration_2
            with document_store.open_session("PyRavenDB") as session:
                replication_document = database.ReplicationDocument([database.ReplicationDestination(
                    url="http://localhost:8080", database="destination_database_name"),
                    database.ReplicationDestination(
                        url="http://localhost:8081", database="destination_database_name")])
                session.store(replication_document)
                session.save_changes()
                # endregion
        except Exception:
            raise
Ejemplo n.º 17
0
    def open_session():
        store = documentstore()
        store.initialize()

        # region open_session_1
        # Open session for a 'default' database configured in 'documentstore'
        with store.open_session() as session:
            session.load("doc/1")
            # code here

        # Open session for a specific database
        with store.open_session(database="Your database") as session:
            session.load("doc/2")
            # code here

        # Open session for a specific database with api_key
        with store.open_session(database="Your database",
                                api_key="API_KEY") as session:
            session.load("doc/3")
Ejemplo n.º 18
0
 def setUpClass(cls):
     super(TestLoad, cls).setUpClass()
     cls.db.put("products/101", {"name": "test"},
                {"Raven-Python-Type": Product.__module__ + ".Product"})
     cls.db.put("products/10", {"name": "test"}, {})
     cls.db.put("orders/105", {
         "name": "testing_order",
         "key": 92,
         "product": "products/101"
     }, {"Raven-Entity-Name": "Orders"})
     cls.db.put("company/1", {
         "name": "test",
         "product": {
             "name": "testing_nested"
         }
     }, {})
     cls.document_store = documentstore(cls.default_url,
                                        cls.default_database)
     cls.document_store.initialize()
    def sample(self):
        try:
            document_store = documentstore()
            # region client_integration_1
            document_store.conventions.failover_behavior = Failover.fail_immediately
            # endregion

            # region client_integration_2
            with document_store.open_session("PyRavenDB") as session:
                replication_document = database.ReplicationDocument([
                    database.ReplicationDestination(
                        url="http://localhost:8080",
                        database="destination_database_name"),
                    database.ReplicationDestination(
                        url="http://localhost:8081",
                        database="destination_database_name")
                ])
                session.store(replication_document)
                session.save_changes()
                # endregion
        except Exception:
            raise
 def setUpClass(cls):
     super(FullTextSearchTest, cls).setUpClass()
     cls.db.put(
         "LastFms/1", {
             "artist": "Tania Maria",
             "track_id": "TRALPJJ128F9311763",
             "title": "Come With Me",
             "datetime_time": datetime.now(),
             "tags": None
         }, {
             "Raven-Entity-Name": "LastFms",
             "Raven-Python-Type": "full_text_search_test.LastFm"
         })
     cls.db.put(
         "LastFms/2", {
             "artist": "Meghan Trainor",
             "track_id": "TRBCNGI128F42597B4",
             "title": "Me Too",
             "datetime_time": datetime.now(),
             "tags": None
         }, {
             "Raven-Entity-Name": "LastFms",
             "Raven-Python-Type": "full_text_search_test.LastFm"
         })
     cls.db.put(
         "LastFms/3", {
             "artist": "Willie Bobo",
             "track_id": "TRAACNS128F14A2DF5",
             "title": "Spanish Grease",
             "datetime_time": datetime.now(),
             "tags": None
         }, {
             "Raven-Entity-Name": "LastFms",
             "Raven-Python-Type": "full_text_search_test.LastFm"
         })
     cls.document_store = documentstore(cls.default_url,
                                        cls.default_database)
     cls.document_store.initialize()
     LastFmAnalyzed().execute(cls.document_store)
Ejemplo n.º 21
0
    def open_session():
        store = documentstore()
        store.initialize()

        # region store_entities_1
        def store(self,
                  entity,
                  key=None,
                  etag=None,
                  force_concurrency_check=False):
            # endregion
            pass

        with store.open_session() as session:
            entity = Employee("first_name", "second_name")
            etag = ""
            # region store_entities_1
            session.store(entity)
            # endregion

            # region store_entities_2
            session.store(entity, etag=etag)
            # endregion

            # region store_entities_3
            session.store(entity, key="doc/1")
            # endregion

            # region store_entities_4
            session.store(entity, key="doc/1", etag=etag)
            # endregion

        with store.open_session() as session:
            # region store_entities_5
            # generate Id automatically
            # when database is new and empty database and conventions are not changed: 'employees/1'
            employee = Employee("John", "Doe")
            session.store(employee)
            session.save_changes()
Ejemplo n.º 22
0
 def setUpClass(cls):
     super(TestQuery, cls).setUpClass()
     cls.index_map = ("from doc in docs "
                      "select new {"
                      "name = doc.name,"
                      "key = doc.key,"
                      "doc_id = (doc.name + \" \") + doc.key}")
     cls.index_sort = IndexDefinition(
         index_map=cls.index_map,
         sort_options={"key": SortOptions.float},
         stores={"doc_id": "Yes"})
     cls.db.put_index("Testing_Sort",
                      index_def=cls.index_sort,
                      overwrite=True)
     cls.db.put("products/101", {
         "name": "test101",
         "key": 2,
         "order": "a"
     }, {
         "Raven-Entity-Name": "Products",
         "Raven-Python-Type": Product.__module__ + ".Product"
     })
     cls.db.put("products/10", {
         "name": "test10",
         "key": 3,
         "order": "b"
     }, {})
     cls.db.put("products/106", {
         "name": "test106",
         "key": 4,
         "order": "c"
     }, {})
     cls.db.put("products/107", {
         "name": "test107",
         "key": 5,
         "order": None
     }, {
         "Raven-Entity-Name": "Products",
         "Raven-Python-Type": Product.__module__ + ".Product"
     })
     cls.db.put("products/103", {
         "name": "test107",
         "key": 6
     }, {
         "Raven-Entity-Name": "Products",
         "Raven-Python-Type": Product.__module__ + ".Product"
     })
     cls.db.put("products/108", {
         "name": "new_testing",
         "key": 90,
         "order": "d"
     }, {
         "Raven-Entity-Name": "Products",
         "Raven-Python-Type": Product.__module__ + ".Product"
     })
     cls.db.put("orders/105", {
         "name": "testing_order",
         "key": 92,
         "product": "products/108"
     }, {"Raven-Entity-Name": "Orders"})
     cls.db.put(
         "company/1", {
             "name": "withNesting",
             "product": {
                 "name": "testing_order",
                 "key": 4,
                 "order": None
             }
         }, {"Raven-Entity-Name": "Companies"})
     cls.db.put("specials/1", {"url": "https://ravendb.net/"})
     cls.db.put(
         "specials/2", {
             "url":
             "http://www.example.com/ebx/LinkResolverServlet?classofcontent=Standard&id=63935",
             "date": "2017.03.05T00:00:00.000"
         })
     cls.db.put("specials/3", {
         "wild_cards": "%~#+!$,;'*[]?*",
         "date": "2017.03.05T00:00:01.000"
     })
     cls.document_store = documentstore(cls.default_url,
                                        cls.default_database)
     cls.document_store.initialize()
 def setUpClass(cls):
     super(TestSessionStore, cls).setUpClass()
     cls.document_store = documentstore(cls.default_url, cls.default_database)
     cls.document_store.initialize()
Ejemplo n.º 24
0
 def setUpClass(cls):
     super(TestSessionStore, cls).setUpClass()
     cls.document_store = documentstore(cls.default_url,
                                        cls.default_database)
     cls.document_store.initialize()
Ejemplo n.º 25
0
from pyravendb.store.document_store import documentstore


class Employee(object):
    def __init__(self, first_name, last_name):
        self.first_name = first_name
        self.last_name = last_name

store = documentstore()
store.initialize()


class LoadingSession(object):
    @staticmethod
    def open_session():

        # region loading_entities_1
        def load(self, key_or_keys, object_type=None, includes=None, nested_object_types=None):
        # endregion

        # region loading_entities_2
        with store.open_session() as session:
            # dynamic_employee will be a DynamicStructure
            employee = session.load("employees/1")
            # endregion

        # region loading_entities_3
        with store.open_session() as session:
            # employee will be Employee object
            employee = session.load("employees/1", object_type=Employee )
            # endregion