⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usage_using_relations.txt

📁 LiteSQL is a C++ library that integrates C++ objects tightly to relational database and thus provide
💻 TXT
字号:
/* LiteSQL - Documentation *  * By Tero Laitinen  *  * See LICENSE for copyright information. *//* \file documentation.txt    Manual *//** \page usage_using_relations Using RelationsA simple database with Person-class and friends-relation.\code<?xml version="1.0"?><!DOCTYPE database SYSTEM "http://litesql.sourceforge.net/litesql.dtd"><database name="TestDatabase" namespace="test">    <object name="Person">        <field name="name" type="string"/>    </object>    <relation name="FriendsRelation">        <relate object="Person" handle="friends"/>        <relate object="Person"/>    </relation></database>    \endcode\section usage_relationclass Relation-classUsually relations are accessed using a relation handle that is attachedto a persistent object. Sometimes, it may be convenient to access relationusing static methods of Relation-class. Methods:- link : link objects- unlink : remove a link between objects- get<type> : get a DataSource<type> of objects- flush : drop all object links- ( getTYPEn : non-template versions for relations with duplicate types )\section usage_relationhandle RelationHandle-classRelation handle is attached to persistent object and it provides convenientaccess to relation. It can be used to link, unlink or select objects related to relation handle's owner.RelationHandle-class' methods:- link- unlink- get<type> : generated for n-ary relations- get : generated for 2-ended relations \section usage_relationhandle_examples RelationHandle-ExamplesA linking example:\codePerson bill(db), bob(db);bill.name = "Bill";bill.update();bob.name = "Bob";bob.update();// both objects must be stored in database before they can be linkedbill.friends.link(bob);// following statement would throw an exception because they are already friends// (friends is bidirectional relation)bob.friends.link(bill);\endcodeA fetching example:\codePerson bob = bill.friends().get(Person::Name == "Bob").one();vector<Person> billsFriends = bill.friends().get().all();\endcodeAn unlinking example:\code// Bill and Bob are no longer friendsbill.friends.unlink(bob);\endcode\section usage_relation_examples Relation-ExamplesSame examples as above converted to static methods of FriendsRelation.A linking example:\codePerson bill(db), bob(db);bill.name = "Bill";bill.update();bob.name = "Bob";bob.update();// both objects must be stored in database before they can be linkedFriendsRelation::link(db, bill, bob);\endcodeA fetching example:\codePerson bob = FriendsRelation::getPerson2(db,                                          Person::Name == "Bob",                                         FriendsRelation::person1==bill.id).one();vector<Person> billsFriends =      FriendsRelation::getPerson2(db, Expr(),                                  FriendsRelation::person1==bill.id).all();\endcodeAn unlinking example:\code// Bill and Bob are no longer friendsFriendsrelation::unlink(bill, bob);\endcode*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -