GithubHelp home page GithubHelp logo

squeryl / squeryl Goto Github PK

View Code? Open in Web Editor NEW
581.0 581.0 137.0 12.29 MB

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

Scala 98.96% Java 1.04%

squeryl's Introduction

maven central javadoc

How to build

  1. Download or clone repository:
    git clone [email protected]:squeryl/squeryl.git
  2. Open a shell in the project's root directory and launch SBT with ./sbt this will fetch the required version of Scala both for SBT itself and for Squeryl.
  3. The 'test' command will run the test suite against the minimalist but very complete H2 database. Type 'package' to create a jar in ./target/[scala version].

For more information

Documentation can be found at The Squeryl Website and Scaladoc. Questions can be directed to the Google Group

squeryl's People

Contributors

ajhcpt avatar anttirt avatar asn-work avatar bchazalet avatar cmaslen avatar davewhittaker avatar dependabot[bot] avatar dflemstr avatar elfolink avatar gekkio avatar github-actions[bot] avatar jaytaylor avatar kevinoid avatar lorrin avatar lucastorri avatar maoe avatar max-l avatar migo avatar mrico avatar pbrant avatar rssh avatar rusho avatar samhendley avatar samskivert avatar scala-steward-bot avatar tych0 avatar waywardmonkeys avatar xuwei-k avatar ymasory avatar zhongsigang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

squeryl's Issues

"Foreing" should be "Foreign"

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!

No such method error refreshing StatefulManyToMany

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

Couldn't make a clone of source

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

A bug in Session object

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

}

Unsupported fields should be rejected early

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).

broken sql generated for tables with non-integer id

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
  );

Support PostgreSQL enum, please :)

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.

Mutable Statements

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.

Add support for DB2

Some of the things the adapter will probably need:

  • Boolean type will need to be either char(1) or smallint. Would be nice to be a setting given people have a preference for either one.
  • timestamp type is timestamp
  • paginated queries will probably need to be overridden. DB2 uses a similar style (if not identical) to Oracle.
  • DB2 supports identity columns (similar to SQL Server) but does not use auto_increment. So I'd say to use sequences as per Oracle.
  • Will need to get the error numbers for the various failures such as table doesn't exist.
  • There will be issues with schemas. Issue 2 would resolve this, but there are workarounds (eg set a default schema in db2cli.ini).

Allow the declaration of schema object prefixes at schema and table level.

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))
)

Can't find @Column ?

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?

Feature Request: Allow custom database types for certain columns

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

  1. Schema wide, by overriding at the Schema trait
  2. Per field, i.e. with an annotation

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)
}

Feature request: POSIX regular expression search operator

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

FieldReferenceLinker._lastAccessedFieldReference bleed-through

http://groups.google.com/group/squeryl/browse_thread/thread/80a0c14e72d5bca/9f1c3d4113161245?lnk=gst&q=bleed#9f1c3d4113161245

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.

Default string length 123?

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?

The repository uses tainted line endings

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:

  1. Emacs complained about it ("DOS emulation mode for Git repository").
  2. Kate complained about it (Incessant "Do you want to convert this DOS text file?" questions).
  3. Git-Flow complained about it (Failed to do a feature branch merge).
  4. Git-Gui complained about it (There were ^M warnings all over the place).

The fix for this is simple:

  1. Maxime and other Windows-users need to issue the command git config --global core.autocrlf true so that files get \r\nendings when they are checked out, and get \n endings again when they are committed back in.
  2. I've made a commit that fixes the issue in dflemstr/Squeryl@e13339c. It looks like every file in the repository has been completely rewritten, but it's only the line endings that are changing. I didn't want to push this to max-l's repository yet, since he hasn't activated auto-CRLF conversion yet.
  3. People who have created forks of the repository should pull in this new change as soon as possible, so that they don't make changes that also use CRLF-endings (because most editors will continue to use CRLF-endings if they open a file with CRLF-endings)
  4. From time to time, a check should be made that no more CRLF endings have crept in. I could do that until further notice.

UUID support

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.

PostgreSQL PK assignment after Table[T].insert(T).

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.

Support string queries (JDBC wrapper)

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 typeArgument data types
refcursorcurs refcursor, name text, filter text
recordid integer, name text, maxcount integer, OUT resultid integer, OUT message text

Spelling errors in identifiers in the code

While the foreign stuff was fixed (thanks!), these things remain as spelling errors in the code:

  • fieldMataData
  • Yeld
  • Correspondance
  • Agregate
  • UniqueIdInAliaseRequired
  • colAnotations
  • courseAssigments
  • SchoolDb2MetableRelations
  • inerpolater
  • Interpolater
  • Convertion

I don't know what's public and what isn't ... Some of them are just in test code also.

FieldMetadata.isAutoIncremented is not set in timely fashion

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.