librelist archives

« back to archive

Configuration of the databases in the config file

Configuration of the databases in the config file

From:
Loic d'Anterroches
Date:
2011-06-22 @ 12:08
Hello,

Photon is supposed to be database agnostic, but, we are all using
databases. If we do not want all the apps to have their own way to write
down the database information in the configuration file, we need to at
least provide the base infrastructure.

What I propose is basically to define:

- How you store server connectivity information in the configuration file.
- How to get a given server connection.
- How to select the given database on the server.

Server connectivity is simple, in the configuration file, you define:

'databases' => array('default' => array('server' => 'localhost',
                                        'engine' => '\photon\db\MySQL',
	                                'key' => 'value'),
                     'mongo' => array('engine' => '\photon\db\Mongo',
                                      'server' =>
'mongodb://sf2.example.com,ny1.example.com',
                                      'options' => array("replicaSet" =>
true),
),

So here you have a mongo and a default database.

Now to get the server connection, I propose something like:

$connection = \photon\db\Connection::get(); // 'default'
$connection = \photon\db\Connection::get('default');
$connection = \photon\db\Connection::get('mongo');

It means that we will need a minimal mapping given the connection data,
get the connection handler. This is pretty simple.

Now, in your app, suppose you use everywhere PostgreSQL but want mongo
to do some logging. You would define in your config file:

'my_log_app.db' => 'mongo',

then in your code:

$connection = \photon\db\Connection::get(Conf::f('my_log_app.db'));

this way, if you do not define the database, it will pick the default
(hopefully a mongo database or it will fail) but you can have multiple
mongo db connection to use one or another, etc.

All the rest, like ORM, ODM, etc. is not covered by Photon. The goal is
just to have consistent configuration and reuse of the database handlers
in the code. The rest is really up to you.

Feedback welcomed,
loïc

--
Indefero - Project management and code hosting - http://www.indefero.net
Photon - High Performance PHP Framework - http://photon-project.com
Céondo Ltd - Web + Science = Fun - http://www.ceondo.com

Re: [photon.users] Configuration of the databases in the config file

From:
Nicolas
Date:
2011-06-23 @ 14:05
Hello,

This looks good to me, mostly because it's really simple :)

Nicolas


On Wed, Jun 22, 2011 at 2:08 PM, Loic d'Anterroches <loic@ceondo.com> wrote:

> Hello,
>
> Photon is supposed to be database agnostic, but, we are all using
> databases. If we do not want all the apps to have their own way to write
> down the database information in the configuration file, we need to at
> least provide the base infrastructure.
>
> What I propose is basically to define:
>
> - How you store server connectivity information in the configuration file.
> - How to get a given server connection.
> - How to select the given database on the server.
>
> Server connectivity is simple, in the configuration file, you define:
>
> 'databases' => array('default' => array('server' => 'localhost',
>                                        'engine' => '\photon\db\MySQL',
>                                        'key' => 'value'),
>                     'mongo' => array('engine' => '\photon\db\Mongo',
>                                      'server' =>
> 'mongodb://sf2.example.com,ny1.example.com',
>                                      'options' => array("replicaSet" =>
> true),
> ),
>
> So here you have a mongo and a default database.
>
> Now to get the server connection, I propose something like:
>
> $connection = \photon\db\Connection::get(); // 'default'
> $connection = \photon\db\Connection::get('default');
> $connection = \photon\db\Connection::get('mongo');
>
> It means that we will need a minimal mapping given the connection data,
> get the connection handler. This is pretty simple.
>
> Now, in your app, suppose you use everywhere PostgreSQL but want mongo
> to do some logging. You would define in your config file:
>
> 'my_log_app.db' => 'mongo',
>
> then in your code:
>
> $connection = \photon\db\Connection::get(Conf::f('my_log_app.db'));
>
> this way, if you do not define the database, it will pick the default
> (hopefully a mongo database or it will fail) but you can have multiple
> mongo db connection to use one or another, etc.
>
> All the rest, like ORM, ODM, etc. is not covered by Photon. The goal is
> just to have consistent configuration and reuse of the database handlers
> in the code. The rest is really up to you.
>
> Feedback welcomed,
> loïc
>
> --
> Indefero - Project management and code hosting - http://www.indefero.net
> Photon - High Performance PHP Framework - http://photon-project.com
> Céondo Ltd - Web + Science = Fun - http://www.ceondo.com
>

Re: [photon.users] Configuration of the databases in the config file

From:
William Martin
Date:
2011-06-24 @ 07:57
Loic, with your code you get an handle to a server, after you need to
select your database everywhere in the code.
Maybe most of the time, an application use only one DB and it's can be
specified in the configuration file ?
It's can be different for you, if you have one DB per
customer/subdomain, here you need some middle-where to handle that.

William

On Thu, Jun 23, 2011 at 4:05 PM, Nicolas <nsebban@gmail.com> wrote:
> Hello,
>
> This looks good to me, mostly because it's really simple :)
>
> Nicolas
>
>
> On Wed, Jun 22, 2011 at 2:08 PM, Loic d'Anterroches <loic@ceondo.com> wrote:
>>
>> Hello,
>>
>> Photon is supposed to be database agnostic, but, we are all using
>> databases. If we do not want all the apps to have their own way to write
>> down the database information in the configuration file, we need to at
>> least provide the base infrastructure.
>>
>> What I propose is basically to define:
>>
>> - How you store server connectivity information in the configuration file.
>> - How to get a given server connection.
>> - How to select the given database on the server.
>>
>> Server connectivity is simple, in the configuration file, you define:
>>
>> 'databases' => array('default' => array('server' => 'localhost',
>>                                        'engine' => '\photon\db\MySQL',
>>                                        'key' => 'value'),
>>                     'mongo' => array('engine' => '\photon\db\Mongo',
>>                                      'server' =>
>> 'mongodb://sf2.example.com,ny1.example.com',
>>                                      'options' => array("replicaSet" =>
>> true),
>> ),
>>
>> So here you have a mongo and a default database.
>>
>> Now to get the server connection, I propose something like:
>>
>> $connection = \photon\db\Connection::get(); // 'default'
>> $connection = \photon\db\Connection::get('default');
>> $connection = \photon\db\Connection::get('mongo');
>>
>> It means that we will need a minimal mapping given the connection data,
>> get the connection handler. This is pretty simple.
>>
>> Now, in your app, suppose you use everywhere PostgreSQL but want mongo
>> to do some logging. You would define in your config file:
>>
>> 'my_log_app.db' => 'mongo',
>>
>> then in your code:
>>
>> $connection = \photon\db\Connection::get(Conf::f('my_log_app.db'));
>>
>> this way, if you do not define the database, it will pick the default
>> (hopefully a mongo database or it will fail) but you can have multiple
>> mongo db connection to use one or another, etc.
>>
>> All the rest, like ORM, ODM, etc. is not covered by Photon. The goal is
>> just to have consistent configuration and reuse of the database handlers
>> in the code. The rest is really up to you.
>>
>> Feedback welcomed,
>> loïc
>>
>> --
>> Indefero - Project management and code hosting - http://www.indefero.net
>> Photon - High Performance PHP Framework - http://photon-project.com
>> Céondo Ltd - Web + Science = Fun - http://www.ceondo.com
>
>



-- 
---------------------------------------------------------
William MARTIN
wysman @NoSpAm@ gmail @DoT@ com

Re: [photon.users] Configuration of the databases in the config file

From:
Loic d'Anterroches
Date:
2011-06-24 @ 08:02

On 2011-06-24 09:57, William MARTIN wrote:
> Loic, with your code you get an handle to a server, after you need to
> select your database everywhere in the code.
> Maybe most of the time, an application use only one DB and it's can be
> specified in the configuration file ?
> It's can be different for you, if you have one DB per
> customer/subdomain, here you need some middle-where to handle that.

Good point. Should we define the database name and automatically
"select" it? I have no problems with it.

loïc

--
Indefero - Project management and code hosting - http://www.indefero.net
Photon - High Performance PHP Framework - http://photon-project.com
Céondo Ltd - Web + Science = Fun - http://www.ceondo.com

> On Thu, Jun 23, 2011 at 4:05 PM, Nicolas <nsebban@gmail.com> wrote:
>> Hello,
>>
>> This looks good to me, mostly because it's really simple :)
>>
>> Nicolas
>>
>>
>> On Wed, Jun 22, 2011 at 2:08 PM, Loic d'Anterroches <loic@ceondo.com> wrote:
>>>
>>> Hello,
>>>
>>> Photon is supposed to be database agnostic, but, we are all using
>>> databases. If we do not want all the apps to have their own way to write
>>> down the database information in the configuration file, we need to at
>>> least provide the base infrastructure.
>>>
>>> What I propose is basically to define:
>>>
>>> - How you store server connectivity information in the configuration file.
>>> - How to get a given server connection.
>>> - How to select the given database on the server.
>>>
>>> Server connectivity is simple, in the configuration file, you define:
>>>
>>> 'databases' => array('default' => array('server' => 'localhost',
>>>                                        'engine' => '\photon\db\MySQL',
>>>                                        'key' => 'value'),
>>>                     'mongo' => array('engine' => '\photon\db\Mongo',
>>>                                      'server' =>
>>> 'mongodb://sf2.example.com,ny1.example.com',
>>>                                      'options' => array("replicaSet" =>
>>> true),
>>> ),
>>>
>>> So here you have a mongo and a default database.
>>>
>>> Now to get the server connection, I propose something like:
>>>
>>> $connection = \photon\db\Connection::get(); // 'default'
>>> $connection = \photon\db\Connection::get('default');
>>> $connection = \photon\db\Connection::get('mongo');
>>>
>>> It means that we will need a minimal mapping given the connection data,
>>> get the connection handler. This is pretty simple.
>>>
>>> Now, in your app, suppose you use everywhere PostgreSQL but want mongo
>>> to do some logging. You would define in your config file:
>>>
>>> 'my_log_app.db' => 'mongo',
>>>
>>> then in your code:
>>>
>>> $connection = \photon\db\Connection::get(Conf::f('my_log_app.db'));
>>>
>>> this way, if you do not define the database, it will pick the default
>>> (hopefully a mongo database or it will fail) but you can have multiple
>>> mongo db connection to use one or another, etc.
>>>
>>> All the rest, like ORM, ODM, etc. is not covered by Photon. The goal is
>>> just to have consistent configuration and reuse of the database handlers
>>> in the code. The rest is really up to you.
>>>
>>> Feedback welcomed,
>>> loïc
>>>
>>> --
>>> Indefero - Project management and code hosting - http://www.indefero.net
>>> Photon - High Performance PHP Framework - http://photon-project.com
>>> Céondo Ltd - Web + Science = Fun - http://www.ceondo.com
>>
>>
> 
> 
>