[jifty-devel] programatically manipulate DB through ORM
Jesse Vincent
jesse at bestpractical.com
Mon Dec 6 14:40:57 EST 2010
On Mon, Dec 06, 2010 at 09:57:51AM -0600, Matt Zagrabelny wrote:
> On Mon, Dec 6, 2010 at 9:26 AM, Jesse Vincent <jesse at bestpractical.com> wrote:
> >
> >
> >
> > On Fri 3.Dec'10 at 16:16:13 -0600, Matt Zagrabelny wrote:
> >> Greetings,
> >>
> >> I am looking to programatically make changes (mostly INSERTs) to a DB
> >> that is part of a Jifty app. Is there a good way to use the Jifty ORM
> >> to do this?
> >
> > Do you mean for something that has Record and Collection classes on the
> > Jifty side or a table in the database that's not under Jifty control?
>
> I believe the former. I'd like to do the majority of database
> modifications (INSERTs) outside of the Jifty web app (instead use a
> perl CLI app)
Now I get it. From your first message it wasn't clear that you meant "outside of the webserver context"
There's actually no reason you can't or shouldn't use Jifty's Model classes from a non-web context.
Here's a cutdown version of our internal "Add a user to the app" program:
#!/usr/bin/env perl
use lib '../Jifty/lib';
use lib 'lib';
use Jifty::Everything;
BEGIN { Jifty->new() }
use BTDT::CurrentUser;
use BTDT::Model::User;
use Getopt::Long;
my $name = 'admin';
GetOptions( 'type=s' => \$type, 'name=s' => \$name);
my $u = BTDT::Model::User->new( current_user => BTDT::CurrentUser->superuser );
my ( $id, $msg ) = $u->create(
name => $name,
password => 'password',
);
print $msg unless ($id);
More information about the jifty-devel
mailing list