Git Product home page Git Product logo

scalikejdbc.github.io's Introduction

ScalikeJDBC website

https://scalikejdbc.org/

How to contribute scalikejdbc.org?

fork scalikejdbc.github.io project

Fork https://github.com/scalikejdbc/scalikejdbc.github.io.

change under the website directory

How to debug:

git clone [your forked repository].
cd scalikejdbc.github.io
gem install bundler
bundle install --path vendor/bundle
# bundle exec middleman build
bundle exec middleman server

Access http://localhost:4567/ from your browser.

make a pull request

Create a branch to request, and send your pull request to develop branch (not master branch).

scalikejdbc.github.io's People

Contributors

admackin avatar aoiroaoino avatar biwkf avatar dependabot[bot] avatar dimitrisli avatar gakuzzzz avatar izumisy avatar kardapoltsev avatar luminescent avatar maowug avatar matil019 avatar no-stupid-questions avatar pchambino avatar reoring avatar saka1 avatar seratch avatar shafiquejamal avatar t-mochizuki avatar taisukeoe avatar taketora26 avatar thobson avatar tkawachi avatar tlazarevic avatar tototoshi avatar tsukaby avatar tsuyoshizawa avatar xuwei-k avatar yamachu avatar yoskhdia avatar zjiajun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scalikejdbc.github.io's Issues

TxBoundary example for an IO monad doesn't work with cats-effect

Nice to meet you!

The TxBoundary example for a hand-made IO monad in the official documentation doesn't work with cats.effect.IO if applied verbatim; finishTx would execute result twice (because cats.effect.IO doesn't memoize), and closeConnection isn't exception-safe. Overall, it appears to be written with eager and memoizing monads (such as Future) in mind.

Fortunately, no changes to the library code are needed to make it work. I was able to create a working TxBoundary for cats.effect.IO:

import scalikejdbc._
import cats.effect._

implicit def catsEffectIOTxBoundary[A]: TxBoundary[IO[A]] = new TxBoundary[IO[A]] {
  def finishTx(result: IO[A], tx: Tx): IO[A] =
    result.guaranteeCase{
      case ExitCase.Completed => IO(tx.commit())
      case _ => IO(tx.rollback())
    }

  override def closeConnection(result: IO[A], doClose: () => Unit): IO[A] =
    result.guarantee(IO(doClose()))
}

The caveat is that DB.localTx itself has to be suspended in IO as well to correctly sequence the effects, like this:

IO.suspend {
  DB.localTx { implicit session =>
    /* IO { ... } */
  }(boundary = catsEffectIOTxBoundary)
}

I think I'm able to write a PR by myself but I have a question: Currently the documentation uses a hand-made monad MyIO but mine uses cats-effect specifics such as IO#guaranteeCase. (attempt can't be used because there are cancellations.) And the IO.suspend thing. Do you think it is OK to add a new example dedicated to cats.effect.IO, or should MyIO section be simply replaced with it?

reverse eingineered tests - syntax `val a` collides with `AWord` from trait `Matchers`

Reproducing

create configuration

# ---
# source code generator settings

generator.packageName=my.fancy.namespace
# generator.lineBreak: LF/CRLF
generator.lineBreak=LF
# generator.template: interpolation/queryDsl
generator.template=queryDsl
# generator.testTemplate: specs2unit/specs2acceptance/ScalaTestFlatSpec
generator.testTemplate=ScalaTestFlatSpec
generator.encoding=UTF-8
# When you're using Scala 2.11 or higher, you can use case classes for 22+ columns tables
generator.caseClassOnly=true
# Set AutoSession for implicit DBSession parameter's default value
generator.defaultAutoSession=true
# Use autoConstruct macro (default: false)
generator.autoConstruct=true
# joda-time (org.joda.time.DateTime) or JSR-310 (java.time.ZonedDateTime java.time.OffsetDateTime java.time.LocalDateTime)
generator.dateTimeClass=java.time.LocalDateTime

run generator

sbt "scalikejdbcGen MyTableName Article"

The reverse engineering routine generates a case class properly.
But...

Problem

The companion object deriving the SQLSyntaxSupport[Article] and the ArticleSpec are not compilable.
The problem here is the val a, which is already defined in Matchers trait.

class ArticleSpec extends fixture.FlatSpec with Matchers with AutoRollback {
  val a = Article.syntax("tpd") // <--- problem is here

  behavior of "Article"
...

Workaround

Manually search/replace a occurences with e.g. s

[scalikejdbc-users-group:123] named schemas support

https://groups.google.com/d/msg/scalikejdbc-users-group/PZew7C4x9us/IWa7v7et1OQJ

Hi,

Thank you for your suggestion. Indeed "def schemaName: Option[String]"
would be worth considering.

Thanks,
-Kaz

On Thu, Dec 19, 2013 at 4:32 AM, Luis Ángel Vicente Sánchez
[email protected] wrote:

I thought it was going to be harder than using the tableName method. I'm
just thinking... adding a method like this,

def schemaName: Option[String]

might be more flexible. You can do something like this to get the final
table name while creating the sql,

List(schemaName, Option(tableName)).flatten.mkString(".")

Anyway... adding the schema name to the table name works for me :D

El miércoles, 18 de diciembre de 2013 00:46:39 UTC+1, Kazuhiro Sera
escribió:

Hi Luis,

It's possible and so simple.

object Member extends SQLSyntaxSupport[Member] {
override def tableName = "public.members"
}

or just sql"select id from public.members".map(_.long(1)).list.apply()

I'll update documentation later.

Thanks,
-Kaz

On Wed, Dec 18, 2013 at 8:35 AM, Luis Ángel Vicente Sánchez
[email protected] wrote:

I have been reading the documentation but I haven't found if scalikejdbc
supports name schemas. Are them supported? Is there any example on how
to
use them?

Regards,

Luis

You received this message because you are subscribed to the Google Groups
"ScalikeJDBC Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

update https://git.io/dbconsole

https://git.io/dbconsole redirect to https://raw.github.com/seratch/scalikejdbc/master/scalikejdbc-cli/scripts/setup.sh not https://raw.github.com/scalikejdbc/scalikejdbc/master/scalikejdbc-cli/scripts/setup.sh 😢

use java.time instead of joda-time in example?

git grep "[jJ]oda"
(without source/documentation/2.x , source/documentation/1.x )

scalikejdbc/scalikejdbc@c72a5d9

source/documentation/reverse-engineering.html.md:import org.joda.time.{LocalDate, DateTime}
source/documentation/reverse-engineering.html.md:import org.joda.time._
source/documentation/setup.html.md.erb:# joda-time (org.joda.time.DateTime) or JSR-310 (java.time.ZonedDateTime java.time.OffsetDateTime java.time.LocalDateTime)
source/documentation/setup.html.md.erb:generator.dateTimeClass=org.joda.time.DateTime
source/documentation/sql-interpolation.html.md.erb:* Time and date types: `java.sql.{Date, Time, Timestamp}`, `java.util.Date`, `org.joda.time.{DateTime, LocalDateTime, LocalDate, LocalTime}`, `java.time.{ZonedDateTime, Instance, LocalDateTime, LocalDate, LocalTime}`
source/documentation/sql-interpolation.html.md.erb:    createdAt  = rs.jodaDateTime(o.createdAt)
source/documentation/testing.html.md:import org.joda.time.DateTime
source/documentation/testing.html.md:import org.joda.time.DateTime
source/documentation/testing.html.md:import org.joda.time.DateTime

Also, We should write about

"org.scalikejdbc" %% "scalikejdbc-joda-time"

dependency.

SQL interpolation behaviour for various parameter types should be documented

Documentation is very boring, but it would be great to have some notes on the SQLInterpolation page about how various passed-in parameter types will be handled. Obviously scalikejdbc knows how to handle particular types. In particular, it seems that numeric types and strings behave exactly as expected. In addition, I know that Scala collection types are converted into a comma-separated list (I've used them, and I still can't remember if wrapping parentheses are added though!). I also think that java.util.Date is handled correctly, as is org.joda.DateTime. Presumably these are special-cased. But what about other classes? What is the algorithm for working out how an instance will be converted to SQL?

I might hope that Option instances would be handled sensibly (wrapped value used if it's Some; SQL null for None). I'm still not sure how 'unknown' classes are handled – does it simply call .toString()?

I could presumably work most of this out by browsing through the source, but in general library users shouldn't be expected to do this for a fairly important feature.

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.