squeryl / squeryl Goto Github PK
View Code? Open in Web Editor NEWA Scala DSL for talking with databases with minimum verbosity and maximum type safety
Home Page: https://squeryl.github.io
License: Apache License 2.0
A Scala DSL for talking with databases with minimum verbosity and maximum type safety
Home Page: https://squeryl.github.io
License: Apache License 2.0
After this discussion: http://groups.google.com/group/squeryl/browse_thread/thread/159c423811acdf9c
Besides virtual method you suggested, there's another idea: maybe it would be ok to introduce special annotation to be used like this:
@SchemaName('dict')
object Dict extends Schema {
val countries = table[Country];
val currencies = table[Currency];
}
@SchemaName('billing')
object Billing extends Schema {
val history = table[History];
}
Here I've shown the way I'd use it: each database schema would correspond to its own Schema instance. Expected Squeryl behaviour is this: if @SchemaName annotation is there, then Query referencing Billing.history would generate SQL with "from billing.history alias" instead of "from history alias".
This also requires that multiple Schema instances can be used together in the single Query:
from(Billing.history, Dict.currencies)((h,c) =>
where(c.id === h.currencyId)
select((h, c))
)
While the foreign stuff was fixed (thanks!), these things remain as spelling errors in the code:
I don't know what's public and what isn't ... Some of them are just in test code also.
The count function needs to take (optional) column arguments.
For examples, see discussion on Squeryl mailing list: http://groups.google.com/group/squeryl/browse_thread/thread/5be2d1dd8d7c6297/3c47cef42fd7248d#3c47cef42fd7248d
schema.printDml must be schema.printDdl, becouse it pring database definition statements, not
database manipulation statements.
Postgres has native UUID support. Other databases can use binary[16] types usually. It would be nice to have support for this natively within Squeryl. I have code that uses UUIDs as that ID for objects and would like to persist them out to a database without too much pain.
It would be nice to have a thin wrapper around JDBC for things that are not (yet) possible to do in squeryl, it could be maybe similar to querolus.
transaction(session){ //this should work in a transaction of the session created by squeryl
val items = for(row <- select("stored","param1",1,2,3) yield {
Item(row.getInt("id"),row.getInt("count"))
}
}
Other use cases would be helpers for stored procedure execution with signatures like these (psql output):
Result data type | Argument data types |
---|---|
refcursor | curs refcursor, name text, filter text |
record | id integer, name text, maxcount integer, OUT resultid integer, OUT message text |
Hi Max,
Evaluating a stateful ManyToMany results in the following:
Exception in thread "main" java.lang.NoSuchMethodError: scala.collection.generic.Growable.$plus$plus$eq(Lscala/collection/Traversable;)Lscala/collection/generic/Growable;
at org.squeryl.dsl.StatefulManyToMany.refresh(ManyToMany.scala:189)
at org.squeryl.dsl.StatefulManyToMany.(ManyToMany.scala:185)
at org.squeryl.dsl.ManyToManyRelation$class.rightStateful(ManyToMany.scala:105)
at org.squeryl.dsl.QueryDsl$ManyToManyRelationImpl.rightStateful(QueryDsl.scala:266)
At first I thought the problem was that the HashMap was not mutable, but the exception indicates that it is a Growable. It seems like this method should exist, so I am puzzled.
-Aled
Statements are immutable by default, this means that even parameters are set once and for all, in some cases it might be desirable to reuse a given statement with new parameters, allowing the preparedStatement to be reused for increased performance.
I am trying to insert into a database for which the schema was created by a previous program. For the first element that I insert, the isAutoIncremented attribute is not set to true. It appears that this is because PosoMetaData.primaryKey is a lazy val, but it has a side-effect of setting isAutoIncremented on the primary key's FieldMetaData.
I don't know why this is a lazy val, but one way to addres it would be in to access posoMetaData.primaryKey in Table.insert prior to calling _dbAdapter.writeInsert.
Reported by Alec Wysoker :
I mentioned previously that sometimes Squeryl produced SQL queries that were
not valid, but I couldn't come up with a good reproduction procedure. I
still don't have a great reproduction procedure independent of my code base,
but after much debugging I have gained some understanding of what is going
on. There is an attribute FieldReferenceLinker._lastAccessedFieldReference.
It looks like this is supposed to be used, then cleared when it is done
being used. It doesn't appear to be getting cleared in all cases. What I
see is that sometimes a value stored in the attribute from a previous
operation bleeds through into the next query, and messes up the query.
I have seen this when using relations like this:
lazy val notificationStatuses =
MySchema.workflowToNotificationStatus.left(this)
I have worked around this problem by doing this:
lazy val notificationStatuses = {
MySchema.clearFieldReferenceLinker
MySchema.workflowToNotificationStatus.left(this)
}
Where MySchema.clearFieldReferenceLinker is
def clearFieldReferenceLinker = (new YieldInspection).cleanUp
I haven't wrapped my head around how this is supposed to work, or if what
I'm doing is the right thing.
Every Git repository needs to use \n
, also known as line feed characters, for its line endings in every text file in the repository, or else there will be problems with merges and/or plain-text patches. The issue is outlined in more detail in the GitHub help pages.
As you all know, Windows uses \r\n
instead for its line endings (carriage return + line feed), and it seems like Maxime hasn't thought about this issue when committing, so the majority (but not all!) of the files in the repository now use the Windows-style line endings. I stumbled upon this fact when:
^M
warnings all over the place).The fix for this is simple:
git config --global core.autocrlf true
so that files get \r\n
endings when they are checked out, and get \n
endings again when they are committed back in.implement it !
Depend only on the lowest common denominator
Should be straight forward. The SQL syntax is very similar to DB2
In Schema.scala
/**
- @return the default database storage (column) length for String columns for this Schema,
- Can be overridden by the Column Annotation ex.: Column(length=256)
- default is 128
*/
def defaultLengthOfString = 123
The default varchar length should be 128 right?
object Session {
private val _currentSessionThreadLocal = new ThreadLocal[Option[Session]] {
override def initialValue = None
}
def cleanupResources =
// TODO: Bug here
if(_currentSessionThreadLocal != None)
_currentSessionThreadLocal.get.get.cleanup
}
I am new to github and may be doing something wrong and bear with me if so. I am getting the error
" fatal : unable to connect a socket (Invalid argument) " error while trying to clone using the command
git clone git://github.com/max-l/Squeryl.git
The "in" operator assumes that it will not receive an empty list as its argument, and fails when it does.
Note : no truncation occurs in the mapping to and from the DB
http://groups.google.com/group/squeryl/browse_thread/thread/b1cb87c9bc5b04c1
When table have non-integer id, generated DML statement include auto_increment.
Example:
class P(override val id:StringField, val descr:StringField) extends KeyedEntity[StringField]
generate
create table P ( descr varchar(123) not null id varchar(123) not null primary key auto_increment );
Schema.scala:
def applyDefaultForeingKeyPolicy(foreingKeyDeclaration: ForeingKeyDeclaration) =
foreingKeyDeclaration.constrainReference
should be
def applyDefaultForeignKeyPolicy(foreignKeyDeclaration: ForeignKeyDeclaration) =
foreignKeyDeclaration.constrainReference
And the problem propagates to the examples that override it. Yes, english is a bastard language, sorry!
Some of the things the adapter will probably need:
If there is at least one outer join, all tables in the from clause with the exception of the first one become "left inner" joined.
Currently, if table.column is of type enum, and generated SQL contains "where table.column = ?" with bound string parameter, PostgreSQL throws:
org.postgresql.util.PSQLException: ERROR: operator does not exist: column = character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Related discussion: http://groups.google.com/group/squeryl/browse_thread/thread/c5866d1a44853700
It would be helpful to allow custom database types for certain columns, i.e. "timestamp with time zone" instead of "timestamp"
Maxime's current idea is:
"I plan to delegate this
method (databaseTypeFor) to the Schema trait, there will two levels where one
can override the default DB type
Of course (2) would have precedence over (1)"
At the moment, a workaround would be (for the timestamp example):
new PostgresSqlAdapter(...) { override def databaseTypeFor(fmd: FieldMetaData) = if(fmd.wrappedFieldType.isInstanceOf[Timestamp]) "timestamp with time zone" else super.databaseTypeFor(fmd) }
All databases currently supported by Squeryl have regular expression search in some way or other. It would be useful for Squeryl to have a "regex" operator that could be used, for example, in the following manner:
[...](n => where%28%28n.name%29 regex%28"^N"%29%29 select%28n%29) [...]
See also http://groups.google.com/group/squeryl/browse_thread/thread/1b41c9f4e46c10c/8d100b5658d9f3c0#8d100b5658d9f3c0 (where you can find out how to implicitly add such a feature yourself, without touching the Squeryl code)
Kind regards,
/nikolaj
Currently Squeryl simply ignores fields of unsupported types in table classes. It should probably throw an exception of some sort for unannotated fields of unsupported types , and provide some sort of annotation to allow fields to exist in table classes that are ignored by Squeryl (like @transient to match the EJB3 persistence annotations).
I got PostgreSQL error:
Exception while executing statement :
insert into Article (id, url, when_last_modified, is_draft, annotation, text, sortOrder, title, when_created) values (nextval('seq_Article'),?,?,?,?,?,?,?,?)
....
Caused by: org.postgresql.util.PSQLException: ERROR: relation "seq_article" does not exist
A sequence name PostgreSQL 8.4 generated for "id serial" field is "article_id_seq", not "seq_article". I suppose there should be Table annotation or so, to provide correct sequence name.
There is a demo in the site:
http://squeryl.org/schema-definition.html
class Book(val id: Long,
13 var title: String,
14 @Column("AUTHOR_ID") // the default 'exact match' policy can be overriden
15 var authorId: Long,
16 var coAuthorId: Option[Long]) {
Note the line 14, there is a Column annotation. But I can't find such a annotation in the release code. Where is wrong?
Per http://groups.google.com/group/squeryl/browse_thread/thread/15f0d52ea2288ee2
I'm envious of the decorators that querulous has for common system concerns for database connection and query resilience. It would be great if Squeryl also provided some help like that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.