SlideShare a Scribd company logo
1 of 50
Download to read offline
Using Document
Databases with
  TYPO3 Flow

            Inspiring people to
            share
Karsten Dambekalns
 TYPO3 Neos and Flow developer
 35 years old
 lives in Lübeck, Germany
 1 wife, 3 sons
 1 espresso machine
 likes canoeing & climbing
Persistence Basics
      in Flow
Flow uses Doctrine 2 ORM


              TYPO3 Flow


              Doctrine ORM
                   Doctrine DBAL

               Native and PDO DB drivers



 MySQL   PostgreSQL                  SQLite   Oracle
Flow provides a centralized
PersistenceManager

   Repository                 DoctrineRepository


      DoctrinePersistenceManager


                Doctrine ORM
                  Doctrine DBAL
Repositories encapsulate
persistence concerns

          Your Application Code


   Repository          DoctrineRepository



      DoctrinePersistenceManager
Models do not know
 about persistence
Models do not know
       (a lot)
 about persistence
    (internals)
Properties
/**
 * @FlowEntity
 */
class Organisation {

   /**
    * The name
    * @var string
    * @FlowValidate(type="NotEmpty")
    * @FlowValidate(type="StringLength", options={"maximum"=40})
    * @ORMColumn(length=40)
    */
   protected $name;
Relations
/**
 * @FlowEntity
 */
class Organisation {

   /**
    * @var DoctrineCommonCollectionsCollection
           <AcmeDemoDomainModelAlias>
    * @ORMOneToMany(mappedBy="organisation",cascade={"persist"})
    * @ORMOrderBy({"name" = "ASC"})
    * @FlowLazy
    */
   protected $aliases;
Document Databases
 Provide some powerful advantages

• schema-less storage
• usually scale well
• really good for non-relational data
 No more Object-Relational Mapping, now you have Object-
 Document Mapping
 Queries, but not as you know them

• Most document databases do not allow queries on arbitary
 properties
Which Database to Choose
 Many different document databases exist
 Which one is right for your project depends on many factors

• MongoDB: For most things that you would do with MySQL or
 PostgreSQL, but having predefined columns really holds you back.

• CouchDB: For accumulating, occasionally changing data, on which
 pre-defined queries are to be run. Places where versioning is
 important.


 A nice overview with much more can be found on
 http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
CouchDB

 Is one of the more widespread products
 Stores documents in JSON
 Provides a REST interface
 Provides master-master replication and MVCC
Futon on CouchDB
CouchDB REST API
 Create a database
 curl -X PUT http://127.0.0.1:5984/demo
 {"ok":true}
 Create documents
 curl -H 'Content-Type: application/json' 
      -X POST http://127.0.0.1:5984/demo 
      -d '{"company": "Example, Inc."}'
 {"ok":true,"id":"8843faaf0b831d364278331bc3001bd8",
 "rev":"1-33b9fbce46930280dab37d672bbc8bb9"}
CouchDB Basics

 Fetch a document
 curl -X GET http://127.0.0.1:5984/demo/
 8843faaf0b831d364278331bc3001bd8
 {"_id":"8843faaf0b831d364278331bc3001bd8",
 "_rev":"1-33b9fbce46930280dab37d672bbc8bb9",
 "company":"Example, Inc."}
CouchDB Basics
 Create a database using Futon or with
 curl -X PUT http://127.0.0.1:5984/demo
 Create documents using Futon or with
 curl -H 'Content-Type: application/json' 
      -X POST http://127.0.0.1:5984/demo 
      -d '{"company": "Example, Inc."}'
 Fetch documents using Futon


 If you do manual work on the shell, try HTTPie instead of cURL
 Read guide.couchdb.org and docs.couchdb.org
CouchDB Basics

 Read guide.couchdb.org and docs.couchdb.org
 Learn about views and map/reduce
Hint: A better cURL
 If you do manual work on the shell, try HTTPie instead of cURL
TYPO3.CouchDB
 Developed for Rossmann by networkteam
 Fully replaces the ORM persistence
 Model annotations stay the same
 Provides basic QOM-to-View mapping


 Note: Not working with TYPO3 Flow 2.0 right now
Installation

   No composer package, so just clone it

cd Packages/Application
git clone git://git.typo3.org/FLOW3/Packages/TYPO3.CouchDB.git
Configuration

TYPO3:
  FLOW3:
    persistence:
       # Options for the CouchDB backend
       backendOptions:
         # database: 'database_name'
         dataSourceName: 'http://127.0.0.1:5984'
         username: ~
         password: ~
         enableCouchdbLucene: no
         driver: ~
         path: ~
Usage – Repository
class TestEntityRepository extends Repository {

    /**
      * @param string $name
      * @return TYPO3FLOW3PersistenceQueryResultInterface
      */
    public function findByNameLike($name) {
        $query = $this->testIndex->createQuery();
        $query->matching(
           $query->like('name', $name)
        );
        return $query->execute();
    }
}
Usage – LuceneIndex
class MyIndex extends TYPO3CouchDBDomainIndexLuceneIndex {

    /**
      * Configure the index
      *
      * @return void
      */
    public function configure() {
         $this->forEntity('AcmeDemoDomainModelSomeEntity')
            ->indexProperty('name')
            ->indexProperty('relatedValueObject.color');
    }

}
Usage – Views & Design Docs
 Views can be defined by
• implementing TYPO3CouchDBViewInterface
• configuring TYPO3CouchDBQueryView

 Design documents can be defined by extending
 TYPO3CouchDBDesignDocument
Now for some
  bad news
Only CouchDB is supported




Kristina Alexanderson
   CC BY-NC-SA 2.0
One Backend at a Time


   Repository                 DoctrineRepository


      DoctrinePersistenceManager


                Doctrine ORM
                  Doctrine DBAL
One Backend at a Time


   Repository                 DoctrineRepository


      DoctrinePersistenceManager


                Doctrine ORM
                  Doctrine DBAL
You can work around this!
 In your repositories you can basically do what you want

• Open a direct database connection
• Read CSV files
• Connect to a Solr server
• Instantiate another Doctrine EntityManager
 Do something more advanced, let Radmiraal.CouchDB inspire you


 As long as you encapsulate nicely!
And now some
 good news
Radmiraal.CouchDB
Radmiraal.CouchDB

 Developed for some projects having similar needs
 Started out as an extension to TYPO3.CouchDB


 Since then refactored & now based on Doctrine 2
 CouchDB ODM
 Can be used alongside the usual ORM
Radmiraal.CouchDB
Radmiraal.CouchDB
Installation

"repositories": [
  {
    "type": "git",
    "url": "https://github.com/radmiraal/Radmiraal.CouchDB.git"
  }
],

"require": {
  "radmiraal/couchdb": "dev-doctrine",
}
Configuration
TYPO3:
  Flow:
    persistence:
       backendOptions:
         … as usual

Radmiraal:
  CouchDB:
    persistence:
      backendOptions:
        databaseName: 'mycouchdb'
        username: 'mycouchuser'
        password: 'mycouchpassw0rd'
Usage – Models
use DoctrineODMCouchDBMappingAnnotations as ODM;

/**
 * @ODMDocument(indexed=true)
 */
class DataSet {

  /**
   * @var string
   * @ODMId(type="string")
   */
  protected $id;

  /**
   * @var AcmeDemoDomainModelOrganisation
Usage – Models
 /**
  * @var AcmeDemoDomainModelOrganisation
  * @ODMField(type="string")
  * @ODMIndex
  */
 protected $organisation;

 /**
  * @var DateTime
  * @ODMField(type="datetime")
  * @ODMIndex
  */
 protected $creationDateTime;
Usage – Repository
class OrganisationBoundaryRepository
 extends RadmiraalCouchDBPersistenceAbstractRepository {

    public function findAll() {
      return $this->createQuery(
        'organisationboundaries', 'by_organisation_id')
        ->execute();
      }
}
Usage – Repository
class DataSetRepository
 extends RadmiraalCouchDBPersistenceAbstractRepository {

    public function findByQuux(Quux $quux) {
      return
       $this->createQuery('datasets', 'most_recent', 'native')
        ->setStartKey(array($this->getQueryMatchValue($quux)))
        ->setGroup(TRUE)
        ->setGroupLevel(1)
        ->setLimit(1)
        ->execute()
}
Usage – Views & Design Docs
And now some
even better news
Multiple backends in parallel

   Doctrine             Doctrine     MongoDB
 Repository          Repository   Repository


               PersistenceManager


         Doctrine ORM               MongoDB ODM
           Doctrine DBAL             Doctrine MongoDB
The Future

 TYPO3 Flow will support multiple persistence backends in
 parallel:

• of the same type: 2 MySQL and 1 PostgreSQL databases
• of different types: MySQL and MongoDB
The Future

 Configuration extended but backwards compatible
 Consistent use independent of backend used:
 Annotations, result interfaces & queries stay consistent


 References across persistence backends? Eventually, but not
 right away…
You can help, too…
 The work on a proper ODM integration so far has been
 done and made possible by (applause!):
• Beech IT
• BKWI
• Rens Admiraal
• myself
 More work is needed, so if you think this is the way to
 go… contact me!
your
questions
       now!
Thank You!
 These slides can be found at:
 http://speakerdeck.com/kdambekalns
 http://slideshare.net/kfish
 Give me feedback: karsten@typo3.org | karsten@dambekalns.de


 Book me: karsten@dambekalns.de
 Follow me on twitter: @kdambekalns
 Support me using
 My Amazon wishlist: http://bit.ly/kdambekalns-wishlist
Using Document Databases with TYPO3 Flow

More Related Content

What's hot

What's hot (20)

Canary deployment with Traefik and K3S
Canary deployment with Traefik and K3SCanary deployment with Traefik and K3S
Canary deployment with Traefik and K3S
 
Quarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesQuarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniques
 
Leveraging the Power of containerd Events - Evan Hazlett
Leveraging the Power of containerd Events - Evan HazlettLeveraging the Power of containerd Events - Evan Hazlett
Leveraging the Power of containerd Events - Evan Hazlett
 
NodeJS: the good parts? A skeptic’s view (devnexus2014)
NodeJS: the good parts? A skeptic’s view (devnexus2014)NodeJS: the good parts? A skeptic’s view (devnexus2014)
NodeJS: the good parts? A skeptic’s view (devnexus2014)
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containers
 
Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
Spring Boot to Quarkus: A real app migration experience | DevNation Tech TalkSpring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
 
Going Reactive with Java
Going Reactive with JavaGoing Reactive with Java
Going Reactive with Java
 
Locking down your Kubernetes cluster with Linkerd
Locking down your Kubernetes cluster with LinkerdLocking down your Kubernetes cluster with Linkerd
Locking down your Kubernetes cluster with Linkerd
 
All Things Open 2017: How to Treat a Network as a Container
All Things Open 2017: How to Treat a Network as a ContainerAll Things Open 2017: How to Treat a Network as a Container
All Things Open 2017: How to Treat a Network as a Container
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
 
Continuous Delivery With Containers
Continuous Delivery With ContainersContinuous Delivery With Containers
Continuous Delivery With Containers
 
Your journey into the serverless world
Your journey into the serverless worldYour journey into the serverless world
Your journey into the serverless world
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
Api versioning w_docker_and_nginx
Api versioning w_docker_and_nginxApi versioning w_docker_and_nginx
Api versioning w_docker_and_nginx
 
Load Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & KubernetesLoad Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & Kubernetes
 
Presentation security automation (Selenium Camp)
Presentation security automation (Selenium Camp)Presentation security automation (Selenium Camp)
Presentation security automation (Selenium Camp)
 
Us 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimesUs 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimes
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
 
Open Source and Secure Coding Practices
Open Source and Secure Coding PracticesOpen Source and Secure Coding Practices
Open Source and Secure Coding Practices
 

Viewers also liked

Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...
George Ang
 
TYPO3 Flow - PHP Framework for Developer Happiness
TYPO3 Flow - PHP Framework for Developer HappinessTYPO3 Flow - PHP Framework for Developer Happiness
TYPO3 Flow - PHP Framework for Developer Happiness
Christian Müller
 
Couch Db In 60 Minutes
Couch Db In 60 MinutesCouch Db In 60 Minutes
Couch Db In 60 Minutes
George Ang
 

Viewers also liked (20)

TYPO3 Flow 2.0 Workshop T3BOARD13
TYPO3 Flow 2.0 Workshop T3BOARD13TYPO3 Flow 2.0 Workshop T3BOARD13
TYPO3 Flow 2.0 Workshop T3BOARD13
 
TYPO3 Flow a solid foundation for medialib.tv
TYPO3 Flow a solid foundation for medialib.tvTYPO3 Flow a solid foundation for medialib.tv
TYPO3 Flow a solid foundation for medialib.tv
 
TYPO3 Flow 2.0 (International PHP Conference 2013)
TYPO3 Flow 2.0 (International PHP Conference 2013)TYPO3 Flow 2.0 (International PHP Conference 2013)
TYPO3 Flow 2.0 (International PHP Conference 2013)
 
T3CON14EU: Migrating from TYPO3 CMS to TYPO3 Flow
T3CON14EU: Migrating from TYPO3 CMS to TYPO3 FlowT3CON14EU: Migrating from TYPO3 CMS to TYPO3 Flow
T3CON14EU: Migrating from TYPO3 CMS to TYPO3 Flow
 
TYPO3 Flow and the Joy of Development (FOSDEM 2013)
TYPO3 Flow and the Joy of Development (FOSDEM 2013)TYPO3 Flow and the Joy of Development (FOSDEM 2013)
TYPO3 Flow and the Joy of Development (FOSDEM 2013)
 
TYPO3 Flow 2.0 in the field - webtech Conference 2013
TYPO3 Flow 2.0 in the field - webtech Conference 2013TYPO3 Flow 2.0 in the field - webtech Conference 2013
TYPO3 Flow 2.0 in the field - webtech Conference 2013
 
T3CON12 Flow and TYPO3 deployment with surf
T3CON12 Flow and TYPO3 deployment with surfT3CON12 Flow and TYPO3 deployment with surf
T3CON12 Flow and TYPO3 deployment with surf
 
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
 
TYPO3 5.0 Experience Concept
TYPO3 5.0 Experience ConceptTYPO3 5.0 Experience Concept
TYPO3 5.0 Experience Concept
 
Couch db and_the_web
Couch db and_the_webCouch db and_the_web
Couch db and_the_web
 
Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...
 
TYPO3 Flow - PHP Framework for Developer Happiness
TYPO3 Flow - PHP Framework for Developer HappinessTYPO3 Flow - PHP Framework for Developer Happiness
TYPO3 Flow - PHP Framework for Developer Happiness
 
Testing TYPO3 Flow Applications with Behat
Testing TYPO3 Flow Applications with BehatTesting TYPO3 Flow Applications with Behat
Testing TYPO3 Flow Applications with Behat
 
Couch Db In 60 Minutes
Couch Db In 60 MinutesCouch Db In 60 Minutes
Couch Db In 60 Minutes
 
TYPO3 Neos - past, present and future (T3CON14EU)
TYPO3 Neos - past, present and future (T3CON14EU)TYPO3 Neos - past, present and future (T3CON14EU)
TYPO3 Neos - past, present and future (T3CON14EU)
 
Couch db
Couch dbCouch db
Couch db
 
Integrating Spark and Solr-(Timothy Potter, Lucidworks)
Integrating Spark and Solr-(Timothy Potter, Lucidworks)Integrating Spark and Solr-(Timothy Potter, Lucidworks)
Integrating Spark and Solr-(Timothy Potter, Lucidworks)
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
 
Comic strip i
Comic strip iComic strip i
Comic strip i
 

Similar to Using Document Databases with TYPO3 Flow

The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...
The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...
The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...
Peter Keane
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
Alvaro Graves
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
bostonrb
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Justin Smestad
 

Similar to Using Document Databases with TYPO3 Flow (20)

The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...
The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...
The Role of Atom/AtomPub in Digital Archive Services at The University of Tex...
 
Guacamole
GuacamoleGuacamole
Guacamole
 
Let your DBAs get some REST(api)
Let your DBAs get some REST(api)Let your DBAs get some REST(api)
Let your DBAs get some REST(api)
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
 
Elasticsearch, Logstash, Kibana. Cool search, analytics, data mining and more...
Elasticsearch, Logstash, Kibana. Cool search, analytics, data mining and more...Elasticsearch, Logstash, Kibana. Cool search, analytics, data mining and more...
Elasticsearch, Logstash, Kibana. Cool search, analytics, data mining and more...
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
MongoDB-presentation.pptx
MongoDB-presentation.pptxMongoDB-presentation.pptx
MongoDB-presentation.pptx
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Doctrine in FLOW3
Doctrine in FLOW3Doctrine in FLOW3
Doctrine in FLOW3
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught Me
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB - A next-generation database that lets you create applications never ...
MongoDB - A next-generation database that lets you create applications never ...MongoDB - A next-generation database that lets you create applications never ...
MongoDB - A next-generation database that lets you create applications never ...
 
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
 
Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
 
CouchDB
CouchDBCouchDB
CouchDB
 
No sq lv1_0
No sq lv1_0No sq lv1_0
No sq lv1_0
 

More from Karsten Dambekalns

The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous project
Karsten Dambekalns
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the future
Karsten Dambekalns
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Karsten Dambekalns
 

More from Karsten Dambekalns (20)

The Perfect Neos Project Setup
The Perfect Neos Project SetupThe Perfect Neos Project Setup
The Perfect Neos Project Setup
 
Sawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosSawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with Neos
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using Surf
 
Profiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsProfiling TYPO3 Flow Applications
Profiling TYPO3 Flow Applications
 
i18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flowi18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flow
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productive
 
The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous project
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the future
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
 
Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developers
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
TDD (with FLOW3)
TDD (with FLOW3)TDD (with FLOW3)
TDD (with FLOW3)
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
Knowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKnowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 Community
 
Unicode & PHP6
Unicode & PHP6Unicode & PHP6
Unicode & PHP6
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0
 
Introduction to Source Code Management
Introduction to Source Code ManagementIntroduction to Source Code Management
Introduction to Source Code Management
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Using Document Databases with TYPO3 Flow

  • 1. Using Document Databases with TYPO3 Flow Inspiring people to share
  • 2. Karsten Dambekalns TYPO3 Neos and Flow developer 35 years old lives in Lübeck, Germany 1 wife, 3 sons 1 espresso machine likes canoeing & climbing
  • 4. Flow uses Doctrine 2 ORM TYPO3 Flow Doctrine ORM Doctrine DBAL Native and PDO DB drivers MySQL PostgreSQL SQLite Oracle
  • 5. Flow provides a centralized PersistenceManager Repository DoctrineRepository DoctrinePersistenceManager Doctrine ORM Doctrine DBAL
  • 6. Repositories encapsulate persistence concerns Your Application Code Repository DoctrineRepository DoctrinePersistenceManager
  • 7. Models do not know about persistence
  • 8. Models do not know (a lot) about persistence (internals)
  • 9. Properties /** * @FlowEntity */ class Organisation { /** * The name * @var string * @FlowValidate(type="NotEmpty") * @FlowValidate(type="StringLength", options={"maximum"=40}) * @ORMColumn(length=40) */ protected $name;
  • 10. Relations /** * @FlowEntity */ class Organisation { /** * @var DoctrineCommonCollectionsCollection <AcmeDemoDomainModelAlias> * @ORMOneToMany(mappedBy="organisation",cascade={"persist"}) * @ORMOrderBy({"name" = "ASC"}) * @FlowLazy */ protected $aliases;
  • 11. Document Databases Provide some powerful advantages • schema-less storage • usually scale well • really good for non-relational data No more Object-Relational Mapping, now you have Object- Document Mapping Queries, but not as you know them • Most document databases do not allow queries on arbitary properties
  • 12. Which Database to Choose Many different document databases exist Which one is right for your project depends on many factors • MongoDB: For most things that you would do with MySQL or PostgreSQL, but having predefined columns really holds you back. • CouchDB: For accumulating, occasionally changing data, on which pre-defined queries are to be run. Places where versioning is important. A nice overview with much more can be found on http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
  • 13. CouchDB Is one of the more widespread products Stores documents in JSON Provides a REST interface Provides master-master replication and MVCC
  • 15. CouchDB REST API Create a database curl -X PUT http://127.0.0.1:5984/demo {"ok":true} Create documents curl -H 'Content-Type: application/json' -X POST http://127.0.0.1:5984/demo -d '{"company": "Example, Inc."}' {"ok":true,"id":"8843faaf0b831d364278331bc3001bd8", "rev":"1-33b9fbce46930280dab37d672bbc8bb9"}
  • 16. CouchDB Basics Fetch a document curl -X GET http://127.0.0.1:5984/demo/ 8843faaf0b831d364278331bc3001bd8 {"_id":"8843faaf0b831d364278331bc3001bd8", "_rev":"1-33b9fbce46930280dab37d672bbc8bb9", "company":"Example, Inc."}
  • 17. CouchDB Basics Create a database using Futon or with curl -X PUT http://127.0.0.1:5984/demo Create documents using Futon or with curl -H 'Content-Type: application/json' -X POST http://127.0.0.1:5984/demo -d '{"company": "Example, Inc."}' Fetch documents using Futon If you do manual work on the shell, try HTTPie instead of cURL Read guide.couchdb.org and docs.couchdb.org
  • 18. CouchDB Basics Read guide.couchdb.org and docs.couchdb.org Learn about views and map/reduce
  • 19. Hint: A better cURL If you do manual work on the shell, try HTTPie instead of cURL
  • 20. TYPO3.CouchDB Developed for Rossmann by networkteam Fully replaces the ORM persistence Model annotations stay the same Provides basic QOM-to-View mapping Note: Not working with TYPO3 Flow 2.0 right now
  • 21. Installation No composer package, so just clone it cd Packages/Application git clone git://git.typo3.org/FLOW3/Packages/TYPO3.CouchDB.git
  • 22. Configuration TYPO3: FLOW3: persistence: # Options for the CouchDB backend backendOptions: # database: 'database_name' dataSourceName: 'http://127.0.0.1:5984' username: ~ password: ~ enableCouchdbLucene: no driver: ~ path: ~
  • 23. Usage – Repository class TestEntityRepository extends Repository { /** * @param string $name * @return TYPO3FLOW3PersistenceQueryResultInterface */ public function findByNameLike($name) { $query = $this->testIndex->createQuery(); $query->matching( $query->like('name', $name) ); return $query->execute(); } }
  • 24. Usage – LuceneIndex class MyIndex extends TYPO3CouchDBDomainIndexLuceneIndex { /** * Configure the index * * @return void */ public function configure() { $this->forEntity('AcmeDemoDomainModelSomeEntity') ->indexProperty('name') ->indexProperty('relatedValueObject.color'); } }
  • 25. Usage – Views & Design Docs Views can be defined by • implementing TYPO3CouchDBViewInterface • configuring TYPO3CouchDBQueryView Design documents can be defined by extending TYPO3CouchDBDesignDocument
  • 26. Now for some bad news
  • 27. Only CouchDB is supported Kristina Alexanderson CC BY-NC-SA 2.0
  • 28. One Backend at a Time Repository DoctrineRepository DoctrinePersistenceManager Doctrine ORM Doctrine DBAL
  • 29. One Backend at a Time Repository DoctrineRepository DoctrinePersistenceManager Doctrine ORM Doctrine DBAL
  • 30. You can work around this! In your repositories you can basically do what you want • Open a direct database connection • Read CSV files • Connect to a Solr server • Instantiate another Doctrine EntityManager Do something more advanced, let Radmiraal.CouchDB inspire you As long as you encapsulate nicely!
  • 31. And now some good news
  • 33. Radmiraal.CouchDB Developed for some projects having similar needs Started out as an extension to TYPO3.CouchDB Since then refactored & now based on Doctrine 2 CouchDB ODM Can be used alongside the usual ORM
  • 36. Installation "repositories": [ { "type": "git", "url": "https://github.com/radmiraal/Radmiraal.CouchDB.git" } ], "require": { "radmiraal/couchdb": "dev-doctrine", }
  • 37. Configuration TYPO3: Flow: persistence: backendOptions: … as usual Radmiraal: CouchDB: persistence: backendOptions: databaseName: 'mycouchdb' username: 'mycouchuser' password: 'mycouchpassw0rd'
  • 38. Usage – Models use DoctrineODMCouchDBMappingAnnotations as ODM; /** * @ODMDocument(indexed=true) */ class DataSet { /** * @var string * @ODMId(type="string") */ protected $id; /** * @var AcmeDemoDomainModelOrganisation
  • 39. Usage – Models /** * @var AcmeDemoDomainModelOrganisation * @ODMField(type="string") * @ODMIndex */ protected $organisation; /** * @var DateTime * @ODMField(type="datetime") * @ODMIndex */ protected $creationDateTime;
  • 40. Usage – Repository class OrganisationBoundaryRepository extends RadmiraalCouchDBPersistenceAbstractRepository { public function findAll() { return $this->createQuery( 'organisationboundaries', 'by_organisation_id') ->execute(); } }
  • 41. Usage – Repository class DataSetRepository extends RadmiraalCouchDBPersistenceAbstractRepository { public function findByQuux(Quux $quux) { return $this->createQuery('datasets', 'most_recent', 'native') ->setStartKey(array($this->getQueryMatchValue($quux))) ->setGroup(TRUE) ->setGroupLevel(1) ->setLimit(1) ->execute() }
  • 42. Usage – Views & Design Docs
  • 43. And now some even better news
  • 44. Multiple backends in parallel Doctrine Doctrine MongoDB Repository Repository Repository PersistenceManager Doctrine ORM MongoDB ODM Doctrine DBAL Doctrine MongoDB
  • 45. The Future TYPO3 Flow will support multiple persistence backends in parallel: • of the same type: 2 MySQL and 1 PostgreSQL databases • of different types: MySQL and MongoDB
  • 46. The Future Configuration extended but backwards compatible Consistent use independent of backend used: Annotations, result interfaces & queries stay consistent References across persistence backends? Eventually, but not right away…
  • 47. You can help, too… The work on a proper ODM integration so far has been done and made possible by (applause!): • Beech IT • BKWI • Rens Admiraal • myself More work is needed, so if you think this is the way to go… contact me!
  • 49. Thank You! These slides can be found at: http://speakerdeck.com/kdambekalns http://slideshare.net/kfish Give me feedback: karsten@typo3.org | karsten@dambekalns.de Book me: karsten@dambekalns.de Follow me on twitter: @kdambekalns Support me using My Amazon wishlist: http://bit.ly/kdambekalns-wishlist