orm

connect SQLAlchemy ORM with the objects from sql core expression?

喜欢而已 提交于 2020-01-23 01:48:05
问题 I have to use SQLalchemy Core expression to fetch objects because ORM can't do "update and returning". (the update in ORM doesn't has returning ) from sqlalchemy import update class User(ORMBase): ... # pure sql expression, the object returned is not ORM object. # the object is a RowProxy. object = update(User) \ .values({'name': 'Wayne'}) \ .where(User.id == subquery.as_scalar()) \ .returning() \ .fetchone() When db_session.add(object) it report UnmappedInstanceError: Class 'sqlalchemy

Java Hibernate/C3P0 error: “Could not obtain connection metadata. An attempt by a client to checkout a Connection has timed out.”

≡放荡痞女 提交于 2020-01-22 17:46:27
问题 I'm trying to get some code I was passed up and running. It appears to use the Hibernate framework. I've gotten past most of the errors tweaking the configuration, but this one has me dead stumped. It's trying to connect to two databases: gameapp and gamelog. Both exist. It seems to have issues connecting to gamelog, but none connecting to gameapp (later in the init, it connects to and loads other DBs just fine). Below, I've pasted the error and exception stack dump. I imaging there's

ORM and layers

天大地大妈咪最大 提交于 2020-01-22 15:19:05
问题 Sorry for this point being all over the place here...but I feel like a dog chasing my tail and I'm all confused at this point. I'm trying to see the cleanest way of developing a 3 tiered solution (IL, BL, DL) where the DL is using an ORM to abstract access to a DB. Everywhere I've seen, people use either LinqToSQL or LLBLGen Pro to generate objects which represent the DB Tables, and refer to those classes in all 3 layers. Seems like 40 years of coding patterns have been ignored -- or a

Django 的简单面试题

别来无恙 提交于 2020-01-22 11:51:01
1. 对Django的认识? #1.Django是走大而全的方向,它最出名的是其全自动化的管理后台:只需要使用起ORM,做简单的对象定义,它就能自动生成数据库结构、以及全功能的管理后台。 #2.Django内置的ORM跟框架内的其他模块耦合程度高。 # 应用程序必须使用Django内置的ORM,否则就不能享受到框架内提供的种种基于其ORM的便利; # 理论上可以切换掉其ORM模块,但这就相当于要把装修完毕的房子拆除重新装修,倒不如一开始就去毛胚房做全新的装修。 #3.Django的卖点是超高的开发效率,其性能扩展有限;采用Django的项目,在流量达到一定规模后,都需要对其进行重构,才能满足性能的要求。 #4.Django适用的是中小型的网站,或者是作为大型网站快速实现产品雏形的工具。 #5.Django模板的设计哲学是彻底的将代码、样式分离; Django从根本上杜绝在模板中进行编码、处理数据的可能。 2. Django 、Flask、Tornado的对比 #1.Django走的是大而全的方向,开发效率高。它的MTV框架,自带的ORM,admin后台管理,自带的sqlite数据库和开发测试用的服务器 #给开发者提高了超高的开发效率 #2.Flask是轻量级的框架,自由,灵活,可扩展性很强,核心基于Werkzeug WSGI工具和jinja2模板引擎 #3

Integrate Doctrine with Zend Framework 1.8 app

空扰寡人 提交于 2020-01-21 08:02:09
问题 I'm interested in using Doctrine as an ORM for a new Zend Framework app I'm writing. I'm trying to figure out the best way to integrate it as straightforward as possible. Every example I find is different, and a lot of them pre-date the new autoloading features in ZF 1.8. None of them have worked for me yet. Does anyone have a good way to do this? I'm inclined to want to place it in my bootstrap file, but some people suggest making a Zend_Application_Resource plugin. The hard part seems to be

构建属于自己的ORM框架之二--IQueryable的奥秘

拜拜、爱过 提交于 2020-01-21 05:52:24
上篇文章标题乱起,被吐槽了,这次学乖了。 上篇文章中介绍了如何解析Expression生成对应的SQL语句,以及IQueryable的一些概念,以及我们所搭建的框架的思想等。但还没把它们结合并应用起来。这一篇文章将更黄更暴力,揭露IQueryable在实际使用中延迟加载的实现原理,结合上篇对Expression的解析,我们来实现一个自己的“延迟加载” 如果还不太了解如何解析Expression和IQueryable的一些基本概念,可以先看看我的 上篇文章 我们先来做些基本工作,定义一个IDataBase接口,里面可以定义些查询,删除,修改,新增等方法,为了节约时间,我们就定义一个查询和删除的方法,再定义一个获取IQueryable<T>实例的方法   public interface IDataBase { List<T> FindAs<T>(Expression<Func<T, bool>> lambdawhere); int Remove<T>(Expression<Func<T, bool>> lambdawhere); IQueryable<T> Source<T>(); } 再添加一个类DBSql,实现我们上面的IDataBase接口,这个类是负责提供对sql数据库的操作 public class DBSql : IDataBase { public List<T>

自己动手写ORM框架(三):关系映射配置—Table属性

房东的猫 提交于 2020-01-21 05:50:59
在上一篇随笔中已经完成了ADO.NET操作数据库的封装,并已经支持多数据库,只需要在配置文件中指定数据库类型即可,本节主要完成对象与数据库表的关系映射配置。 下面看表名的映射配置代码块1-1: [Table(Name="Student")] public class StudentEntity { //...........省略 } 在类上面用[Table(name = ” Student ")]属性来配置,表示该实体类StudentEntity与数据库中的 Student 表进行关系映射。 Table属性需要自己编写,代码块1-2: using System; using System.Collections.Generic; using System.Text; namespace System.Orm.CustomAttributes { [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public class TableAttribute : Attribute { private string _Name = string.Empty; public TableAttribute() {} public string Name { get { return

How to avoid this very heavy query that slows down the application?

与世无争的帅哥 提交于 2020-01-21 05:09:23
问题 We have a web application running in a production enviroment and at some point the client complained about how slow the application got. When we checked what was going on with the application and the database we discover this "precious" query that was being executed by several users at the same time (thus inflicting an extremely high load on the database server): SELECT NULL AS table_cat, o.owner AS table_schem, o.object_name AS table_name, o.object_type AS table_type, NULL AS remarks FROM

how using SQL IN operator in find method of cakephp ORM

六眼飞鱼酱① 提交于 2020-01-20 04:02:28
问题 i am beginner in cakephp , and i want use SQL IN operator in find method , i have words table. my code is : $this->Word->find('Word.wordid in (83,82)'); , and this code create this query : SELECT `Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, `Userword`.`date`, `Userword`.`levelid` FROM `userwords` AS `Userword` WHERE `Userword`.`wordid` = (82) but i need this query SELECT `Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, Userword`.`date`, `Userword`.

Django自带mysql orm操作插入外键的正确打开方式

会有一股神秘感。 提交于 2020-01-19 16:50:57
在给网站数据库优化的过程中,需要给几张表增加外键限制,方便管理员界面的联表操作。 调研发现,网上提供的几种models的配置都不能让我的插入程序成功运行,在经过尝试之后总结出了一个终极解决方案。 我的环境:Django==2.1.7,Python==3.6.1 我建表一般先过Navicat这种可视化软件来生成mysql数据库,所以我们直接在建表之后使用下面语句直接生成。 python manage.py inspectdb > app/models.py // 'app' 是我项目名称 生成的models.py部分代码: class InfoUpload(models.Model): # 子表 upload_id = models.AutoField(primary_key=True) contact_email = models.ForeignKey('InfoUser', model.DO_NOTHING, db_column='contact_email') class Meta: managed = False db_table = 'info_upload' class InfoUser(models.Model): # 主表 user_id = models.AutoField(primary_key=True) contact_email = models