or query in flask_SQLAlchemy [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
Using OR in SQLAlchemy
5 answers
I am porting my old code where I had used mysql library for querying mysql. I am tyring to use flask_SQLALchemy to do the same but unable to find alternate option to query 'or'.
Below is a snippet from updated code on how it's working.
from flask_sqlalchemy import SQLAlchemy
from myapp import APP
from myapp.models.nodes import Host
DB = SQLAlchemy(APP)
# config is taken care here
APP.app_context().push()
with APP.app_context():
DB.init_app(APP)
Hostname_var = "some hostname"
session_query = Host.query.filter_by(hostname=hostname_var).first()
Similarily, I want to query statement given below. I could use sqlalchemy but using different libraries doesn't sound ideal.
"Select count(*) as c from table_name where ver='some version' and arch='some arch' and pool=1 and (state='Ready' or state='Provisioning');"
table_name's class is called Host (as used in example).
Any help is appreciated, thanks.
python flask sqlalchemy flask-sqlalchemy mysql-python
marked as duplicate by Ilja Everilä
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 21:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
Using OR in SQLAlchemy
5 answers
I am porting my old code where I had used mysql library for querying mysql. I am tyring to use flask_SQLALchemy to do the same but unable to find alternate option to query 'or'.
Below is a snippet from updated code on how it's working.
from flask_sqlalchemy import SQLAlchemy
from myapp import APP
from myapp.models.nodes import Host
DB = SQLAlchemy(APP)
# config is taken care here
APP.app_context().push()
with APP.app_context():
DB.init_app(APP)
Hostname_var = "some hostname"
session_query = Host.query.filter_by(hostname=hostname_var).first()
Similarily, I want to query statement given below. I could use sqlalchemy but using different libraries doesn't sound ideal.
"Select count(*) as c from table_name where ver='some version' and arch='some arch' and pool=1 and (state='Ready' or state='Provisioning');"
table_name's class is called Host (as used in example).
Any help is appreciated, thanks.
python flask sqlalchemy flask-sqlalchemy mysql-python
marked as duplicate by Ilja Everilä
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 21:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
Using OR in SQLAlchemy
5 answers
I am porting my old code where I had used mysql library for querying mysql. I am tyring to use flask_SQLALchemy to do the same but unable to find alternate option to query 'or'.
Below is a snippet from updated code on how it's working.
from flask_sqlalchemy import SQLAlchemy
from myapp import APP
from myapp.models.nodes import Host
DB = SQLAlchemy(APP)
# config is taken care here
APP.app_context().push()
with APP.app_context():
DB.init_app(APP)
Hostname_var = "some hostname"
session_query = Host.query.filter_by(hostname=hostname_var).first()
Similarily, I want to query statement given below. I could use sqlalchemy but using different libraries doesn't sound ideal.
"Select count(*) as c from table_name where ver='some version' and arch='some arch' and pool=1 and (state='Ready' or state='Provisioning');"
table_name's class is called Host (as used in example).
Any help is appreciated, thanks.
python flask sqlalchemy flask-sqlalchemy mysql-python
This question already has an answer here:
Using OR in SQLAlchemy
5 answers
I am porting my old code where I had used mysql library for querying mysql. I am tyring to use flask_SQLALchemy to do the same but unable to find alternate option to query 'or'.
Below is a snippet from updated code on how it's working.
from flask_sqlalchemy import SQLAlchemy
from myapp import APP
from myapp.models.nodes import Host
DB = SQLAlchemy(APP)
# config is taken care here
APP.app_context().push()
with APP.app_context():
DB.init_app(APP)
Hostname_var = "some hostname"
session_query = Host.query.filter_by(hostname=hostname_var).first()
Similarily, I want to query statement given below. I could use sqlalchemy but using different libraries doesn't sound ideal.
"Select count(*) as c from table_name where ver='some version' and arch='some arch' and pool=1 and (state='Ready' or state='Provisioning');"
table_name's class is called Host (as used in example).
Any help is appreciated, thanks.
This question already has an answer here:
Using OR in SQLAlchemy
5 answers
python flask sqlalchemy flask-sqlalchemy mysql-python
python flask sqlalchemy flask-sqlalchemy mysql-python
asked Nov 20 at 14:50
SiddharthVipul
34
34
marked as duplicate by Ilja Everilä
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 21:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Ilja Everilä
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 21:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You need to use |
and &
, such as:
Host.query.filter(
(Host.ver == 'some version') & (Host.arch == 'some arch') & (Host.pool == 1) &
((Host.state == 'Ready') | (Host.state == 'Provisioning'))
).count()
would give you desired result.
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You need to use |
and &
, such as:
Host.query.filter(
(Host.ver == 'some version') & (Host.arch == 'some arch') & (Host.pool == 1) &
((Host.state == 'Ready') | (Host.state == 'Provisioning'))
).count()
would give you desired result.
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
add a comment |
up vote
0
down vote
accepted
You need to use |
and &
, such as:
Host.query.filter(
(Host.ver == 'some version') & (Host.arch == 'some arch') & (Host.pool == 1) &
((Host.state == 'Ready') | (Host.state == 'Provisioning'))
).count()
would give you desired result.
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You need to use |
and &
, such as:
Host.query.filter(
(Host.ver == 'some version') & (Host.arch == 'some arch') & (Host.pool == 1) &
((Host.state == 'Ready') | (Host.state == 'Provisioning'))
).count()
would give you desired result.
You need to use |
and &
, such as:
Host.query.filter(
(Host.ver == 'some version') & (Host.arch == 'some arch') & (Host.pool == 1) &
((Host.state == 'Ready') | (Host.state == 'Provisioning'))
).count()
would give you desired result.
answered Nov 20 at 15:15
vishes_shell
9,96633645
9,96633645
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
add a comment |
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
wow, I really remember trying this. thanks a lot. It worked
– SiddharthVipul
Nov 20 at 19:34
add a comment |