SQLObject 下的数据库更改
我正在启动一个可能适合 SQLite 的 Web 项目。 我在其之上有 SQLObject,但在这里考虑长远 - 如果这个项目需要更健壮(例如能够处理高流量),我将需要准备好一个过渡计划。 我的问题:
- 在 SQLObject 下从一个数据库(SQLite)转换到另一个数据库(MySQL 或 Firebird 或 PostGre)有多容易?
- SQLObject 是否提供任何工具来使这种转换变得更容易? 它只是简单地获取我定义的对象并调用 createTable 吗?
- 拥有多个 SQLite 数据库怎么样? 例如,每个访客组一个? SQLObject 是否提供了处理这种情况的机制?如果是,该使用什么机制?
谢谢, 肖恩
I'm starting a web project that likely should be fine with SQLite. I have SQLObject on top of it, but thinking long term here -- if this project should require a more robust (e.g. able to handle high traffic), I will need to have a transition plan ready. My questions:
- How easy is it to transition from one DB (SQLite) to another (MySQL or Firebird or PostGre) under SQLObject?
- Does SQLObject provide any tools to make such a transition easier? Is it simply take the objects I've defined and call createTable?
- What about having multiple SQLite databases instead? E.g. one per visitor group? Does SQLObject provide a mechanism for handling this scenario and if so, what is the mechanism to use?
Thanks,
Sean
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
3)这是一个非常有趣的问题。 一般来说,SQLite 对于基于 Web 的东西来说毫无用处。 它的大小可扩展性相当好,但并发性的可扩展性却非常糟糕,因此,如果您计划同时处理几个请求,那么您就会遇到麻烦。
现在,问题第 3) 部分的想法是使用多个 SQLite 数据库(例如,每个用户组一个,甚至每个用户一个)。 不幸的是,SQLite 在这方面不会给你任何帮助。 但这是可能的。 我知道之前做过此操作的一个项目是 Divmod 的 Axiom。 所以我肯定会检查一下。
当然,使用像您提到的那样的良好并发数据库(Firebird、PG 等)可能会容易得多。
为了完整性:
1 和 2)它应该很简单,而无需您实际编写很多代码。 我发现 SQLObject 在这个部门有点限制,强烈推荐 SQLAlchemy 。 这要灵活得多,如果我今天开始一个新项目,我肯定会使用它而不是 SQLObject。 它不会将“对象”移动到任何地方。 这里没有涉及任何魔法,它将传输数据库中表中的行。 正如前面提到的,您可以手动完成,但这可能会节省您一些时间。
3) Is quite an interesting question. In general, SQLite is pretty useless for web-based stuff. It scales fairly well for size, but scales terribly for concurrency, and so if you are planning to hit it with a few requests at the same time, you will be in trouble.
Now your idea in part 3) of the question is to use multiple SQLite databases (eg one per user group, or even one per user). Unfortunately, SQLite will give you no help in this department. But it is possible. The one project I know that has done this before is Divmod's Axiom. So I would certainly check that out.
Of course, it would probably be much easier to just use a good concurrent DB like the ones you mention (Firebird, PG, etc).
For completeness:
1 and 2) It should be straightforward without you actually writing much code. I find SQLObject a bit restrictive in this department, and would strongly recommend SQLAlchemy instead. This is far more flexible, and if I was starting a new project today, I would certainly use it over SQLObject. It won't be moving "Objects" anywhere. There is no magic involved here, it will be transferring rows in tables in a database. Which as mentioned you could do by hand, but this might save you some time.
您使用 createTable() 的成功将取决于您现有的基础表架构/数据类型。 换句话说,SQLite 映射到您选择的数据库的程度以及 SQLObject 如何决定使用您的数据类型。
最安全的选择可能是手动创建新数据库。 然后,您必须处理数据迁移,这可能就像在同一表定义上实例化两个 SQLObject 数据库连接一样简单。
为什么不从功能更齐全的数据库开始呢?
Your success with createTable() will depend on your existing underlying table schema / data types. In other words, how well SQLite maps to the database you choose and how SQLObject decides to use your data types.
The safest option may be to create the new database by hand. Then you'll have to deal with data migration, which may be as easy as instantiating two SQLObject database connections over the same table definitions.
Why not just start with the more full-featured database?
我不确定我是否理解这个问题。
SQLObject 文档列出了六种可用的连接。 此外,数据库连接(或方案)在连接字符串中指定。 将数据库连接从 SQLite 更改为 MySQL 非常简单。 只需更改连接字符串即可。
文档列出了受支持的不同类型的方案。
I'm not sure I understand the question.
The SQLObject documentation lists six kinds of connections available. Further, the database connection (or scheme) is specified in a connection string. Changing database connections from SQLite to MySQL is trivial. Just change the connection string.
The documentation lists the different kinds of schemes that are supported.