database-agnostic

Changing timezone on an existing Django project

隐身守侯 提交于 2019-12-10 13:43:44
问题 Like an idiot, I completely overlooked the timezone setting when I first built an application that collects datetime data. It wasn't an issue then because all I was doing was "time-since" style comparisons and ordering. Now I need to do full reports that show the actual datetime and of course, they're all stored at America/Chicago (the ridiculous Django default). So yes. I've got a medium sized database full of these dates that are incorrect. I want to change settings.TIME_ZONE to 'UTC' but

Slick generic AND driver agnostic

瘦欲@ 提交于 2019-12-09 02:02:28
问题 Basically what I want to achieve is a combination of: Slick 3.0.0 database agnostism and Slick 3 reusable generic repository I tried a lot, actually, but I can't get this to work at all. abstract class BaseModel[T <: slick.lifted.AbstractTable[_]](query: TableQuery[T], val driver: JdbcProfile, val dbTableName: String) { lazy val all: TableQuery[T] = TableQuery[T] import driver.api._ def createTable = all.schema.create def dropTable = all.schema.create abstract class BaseTable[B](val tag: Tag)

Rails: Making this query database-agnostic…?

℡╲_俬逩灬. 提交于 2019-12-08 04:13:03
问题 I have these two lines in my model, written for PostgreSQL: named_scope :by_month, lambda { |month| { :conditions => ["EXTRACT(MONTH FROM recorded_on) = ?", month] }} named_scope :by_year, lambda { |year| { :conditions => ["EXTRACT(YEAR FROM recorded_on) = ?", year] }} I'm running PostgreSQL in production, but I'm developing with SQLite3. How can I write those lines in a way that is database-agnostic? Btw, "recorded_on" is formed from the following: Model.recorded_on = Time.parse("Fri, 01 May

Rails: Making this query database-agnostic…?

廉价感情. 提交于 2019-12-06 22:12:42
I have these two lines in my model, written for PostgreSQL: named_scope :by_month, lambda { |month| { :conditions => ["EXTRACT(MONTH FROM recorded_on) = ?", month] }} named_scope :by_year, lambda { |year| { :conditions => ["EXTRACT(YEAR FROM recorded_on) = ?", year] }} I'm running PostgreSQL in production, but I'm developing with SQLite3. How can I write those lines in a way that is database-agnostic? Btw, "recorded_on" is formed from the following: Model.recorded_on = Time.parse("Fri, 01 May 2009 08:42:23 -0400") Okay, found out there's a better way (thanks to this article ): Basically do

How to construct query in querydsl without domain classes

老子叫甜甜 提交于 2019-12-05 20:08:44
While looking for java libraries to build queries in a database agnostic way I came across many including iciql, querydsl, jooq, joist, hibernate etc. I wanted something that does not require configuration files and can work with dynamic schemas. For my application, I come to know about the database and the schema at runtime so I won't have any configuration files or domain classes for the schema. This seems to be one of the core goals of querydsl but going through the documentation for querydsl I see a lot of examples for building dynamic queries using domain classes but I have not come

DB agnostic SQL for CURRENT_TIMESTAMP

筅森魡賤 提交于 2019-12-05 03:22:31
I'm currently using Oracle, but most of the SQL is db agnostic. One exception is CURRENT_TIMESTAMP which fails in MSSQL. Is is possible to move to a more portable syntax for this too? According to their documentation the following vendors support CURRENT_TIMESTAMP . Oracle Postgresql MySQL SQL Server Firebird H2 HSQLDB DB2 Vertica InterSystems Caché Doctrine Teradata In summary, CURRENT_TIMESTAMP is the method stated in the SQL Standard, a summary of which is below, and if you are looking for DB agnostic SQL the best you can really do is stick to the standard, although this does not guarantee

What data type is recommended for ID columns?

[亡魂溺海] 提交于 2019-12-04 13:10:52
问题 I realize this question is very likely to have been asked before, but I've searched around a little among questions on StackOverflow, and I didn't really find an answer to mine, so here goes. If you find a duplicate, please link to it. For some reason I prefer to use Guid s ( uniqueidentifier in MsSql) for my primary key fields, but I really don't know why this would be better. In many of tutorials I've walked myself through lately an automatically incremented int has been used. I can see pro

Does “group by” automatically guarantee “order by”?

烂漫一生 提交于 2019-12-04 01:51:04
Does "group by" clause automatically guarantee that the results will be ordered by that key? In other words, is it enough to write: select * from table group by a, b, c or does one have to write select * from table group by a, b, c order by a, b, c I know e.g. in MySQL I don't have to, but I would like to know if I can rely on it accross the SQL implementations. Is it guaranteed? juergen d group by does not order the data neccessarily. A DB is designed to grab the data as fast as possible and only sort if necessary. So add the order by if you need a guaranteed order. An efficient

Should Many to Many Tables Have a Primary Key?

て烟熏妆下的殇ゞ 提交于 2019-12-03 15:44:20
问题 If I have two objects that have a many-to-many relationship, I would typically model them in my database schema with a many-to-many table to relate the two. But should that many-to-many table (or "join table") have a primary key of its own (integer auto-incremented)? For example, I might have tables A and B, each with an ID, and a table called A_B that has a foreign key tuple of (A_ID, B_ID). But should A_B have a primary key auto-incremented ID column of its own, or not? What are the

What data type is recommended for ID columns?

不羁岁月 提交于 2019-12-03 07:25:55
I realize this question is very likely to have been asked before, but I've searched around a little among questions on StackOverflow, and I didn't really find an answer to mine, so here goes. If you find a duplicate, please link to it. For some reason I prefer to use Guid s ( uniqueidentifier in MsSql) for my primary key fields, but I really don't know why this would be better. In many of tutorials I've walked myself through lately an automatically incremented int has been used. I can see pro's and cons with both: A Guid is always of the same size and length, and there is no reason to worry