我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用sqlalchemy.null()。
def __init__(self, none_as_null=False): """Construct a :class:`.JSON` type. :param none_as_null: if True, persist the value ``None`` as a SQL NULL value, not the JSON encoding of ``null``. Note that when this flag is False, the :func:`.null` construct can still be used to persist a NULL value:: from sqlalchemy import null conn.execute(table.insert(), data=null()) .. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null` is now supported in order to persist a NULL value. """ self.none_as_null = none_as_null
def __init__(self, none_as_null=False): """Construct a :class:`.types.JSON` type. :param none_as_null=False: if True, persist the value ``None`` as a SQL NULL value, not the JSON encoding of ``null``. Note that when this flag is False, the :func:`.null` construct can still be used to persist a NULL value:: from sqlalchemy import null conn.execute(table.insert(), data=null()) .. note:: :paramref:`.JSON.none_as_null` does **not** apply to the values passed to :paramref:`.Column.default` and :paramref:`.Column.server_default`; a value of ``None`` passed for these parameters means "no default present". .. seealso:: :attr:`.types.JSON.NULL` """ self.none_as_null = none_as_null
def __init__(self, none_as_null=False): """Construct a :class:`.types.JSON` type. :param none_as_null=False: if True, persist the value ``None`` as a SQL NULL value, not the JSON encoding of ``null``. Note that when this flag is False, the :func:`.null` construct can still be used to persist a NULL value:: from sqlalchemy import null conn.execute(table.insert(), data=null()) .. seealso:: :attr:`.types.JSON.NULL` """ self.none_as_null = none_as_null
def build_full_day_ips(query, period_start, period_end): """Method to build an IP list for the case 1 when the IP was allocated before the period start and is still allocated after the period end. This method only looks at public IPv4 addresses. """ # Filter out only IPv4 that have not been deallocated ip_list = query.\ filter(models.IPAddress.version == 4L).\ filter(models.IPAddress.network_id == PUBLIC_NETWORK_ID).\ filter(models.IPAddress.used_by_tenant_id is not None).\ filter(models.IPAddress.allocated_at != null()).\ filter(models.IPAddress.allocated_at < period_start).\ filter(or_(models.IPAddress._deallocated is False, models.IPAddress.deallocated_at == null(), models.IPAddress.deallocated_at >= period_end)).all() return ip_list
def build_partial_day_ips(query, period_start, period_end): """Method to build an IP list for the case 2 when the IP was allocated after the period start and is still allocated after the period end. This method only looks at public IPv4 addresses. """ # Filter out only IPv4 that were allocated after the period start # and have not been deallocated before the period end. # allocated_at will be set to a date ip_list = query.\ filter(models.IPAddress.version == 4L).\ filter(models.IPAddress.network_id == PUBLIC_NETWORK_ID).\ filter(models.IPAddress.used_by_tenant_id is not None).\ filter(and_(models.IPAddress.allocated_at != null(), models.IPAddress.allocated_at >= period_start, models.IPAddress.allocated_at < period_end)).\ filter(or_(models.IPAddress._deallocated is False, models.IPAddress.deallocated_at == null(), models.IPAddress.deallocated_at >= period_end)).all() return ip_list
def __init__(self, none_as_null=False, astext_type=None): """Construct a :class:`.JSON` type. :param none_as_null: if True, persist the value ``None`` as a SQL NULL value, not the JSON encoding of ``null``. Note that when this flag is False, the :func:`.null` construct can still be used to persist a NULL value:: from sqlalchemy import null conn.execute(table.insert(), data=null()) .. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null` is now supported in order to persist a NULL value. .. seealso:: :attr:`.JSON.NULL` :param astext_type: the type to use for the :attr:`.JSON.Comparator.astext` accessor on indexed attributes. Defaults to :class:`.types.Text`. .. versionadded:: 1.1 """ super(JSON, self).__init__(none_as_null=none_as_null) if astext_type is not None: self.astext_type = astext_type
def render_with_navbar(template, **kwargs): # unions Links and Pages, then sorts by index query_pages = Page.query.with_entities(Page.id_, Page.title, Page.name, sqlalchemy.null().label("url"), Page.index, Page.category, Page.divider_below) query_links = Link.query.with_entities(Link.id_, Link.title, sqlalchemy.null().label("name"), Link.url, Link.index, Link.category, Link.divider_below) query_all = query_pages.union_all(query_links).order_by(Page.index) pages = OrderedDict([('Hidden', query_all.filter_by(category='Hidden').all()), ('Calendars', query_all.filter_by(category='Calendars').all()), ('About Us', query_all.filter_by(category='About Us').all()), ('Academics', query_all.filter_by(category='Academics').all()), ('Students', query_all.filter_by(category='Students').all()), ('Parents', query_all.filter_by(category='Parents').all()), ('Admissions', query_all.filter_by(category='Admissions').all())]) return render_template(template, pages=pages, **kwargs)
def active(self): now = session.now_sql() return and_(self.start_date <= now, or_(self.end_date == null(), self.end_date > now))
def group(self, group, current=None): # Filter by group sub_query = db.session.query(GroupPatient) sub_query = sub_query.filter(GroupPatient.group == group, GroupPatient.patient_id == Patient.id) if current is not None: if current: # Between from and to date sub_query = sub_query.filter( GroupPatient.from_date <= func.now(), or_( GroupPatient.to_date == null(), GroupPatient.to_date >= func.now(), ) ) else: # Outside from or to date sub_query = sub_query.filter(or_( GroupPatient.from_date > func.now(), and_( GroupPatient.to_date != null(), GroupPatient.to_date < func.now() ) )) self.query = self.query.filter(sub_query.exists()) return self
def export_lab_orders(sda_container, patient, group): q = Result.query q = q.filter(Result.patient == patient) q = q.filter(Result.source_group == group) q = q.filter(Result.source_type == SOURCE_TYPE_MANUAL) q = q.join(Result.observation) q = q.filter(Observation.pv_code != null()) results = q.all() if not results: return sda_lab_orders = sda_container.setdefault('lab_orders', list()) for result in results: sda_lab_order = { 'external_id': str(result.id), 'order_item': { 'sda_coding_standard': 'PV', 'code': result.observation.pv_code, 'description': result.observation.pv_code }, 'result': { 'result_time': result.date, 'result_items': [ { 'observation_time': result.date, 'test_item_code': { 'sda_coding_standard': 'PV', 'code': result.observation.pv_code, 'description': result.observation.pv_code }, 'result_value': str(result.value) } ] }, 'entering_organization': { 'code': result.source_group.code, 'description': result.source_group.name }, 'entered_at': { 'code': 'RADAR', 'description': 'RaDaR' } } sda_lab_orders.append(sda_lab_order)