• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala BSONDateTime类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中reactivemongo.bson.BSONDateTime的典型用法代码示例。如果您正苦于以下问题:Scala BSONDateTime类的具体用法?Scala BSONDateTime怎么用?Scala BSONDateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BSONDateTime类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Common

//设置package包名称以及导入依赖的类
package models


import java.util.Date
import reactivemongo.bson.{BSONDateTime,BSONReader,BSONWriter}

object Common {
  val objectIdRegEx = """[a-fA-F0-9]{24}""".r
}

object BSONProducers {
  implicit object DateWriter extends BSONWriter[Date,BSONDateTime]{
    def write(dt:Date) : BSONDateTime = BSONDateTime(dt.getTime)
  }
  implicit object DateReader extends BSONReader[BSONDateTime,Date]{
    def read(dt:BSONDateTime) : Date = new Date(dt.value)
  }
} 
开发者ID:nabirdinani,项目名称:MySurvey,代码行数:19,代码来源:Common.scala


示例2: write

//设置package包名称以及导入依赖的类
package de.choffmeister.microserviceutils.mongodb.bson

import java.time.Instant

import reactivemongo.bson.{BSONDateTime, BSONLong, BSONReader, BSONValue, BSONWriter}

trait InstantBSONProtocol {
  implicit val instantReaderWriter = new BSONReader[BSONValue, Instant] with BSONWriter[Instant, BSONDateTime] {
    override def write(t: Instant): BSONDateTime = BSONDateTime(t.toEpochMilli)
    override def read(bson: BSONValue): Instant = bson match {
      case BSONDateTime(value) => Instant.ofEpochMilli(value)
      case BSONLong(value) => Instant.ofEpochMilli(value)
      case _ => throw new RuntimeException()
    }
  }
} 
开发者ID:choffmeister,项目名称:microservice-utils,代码行数:17,代码来源:InstantBSONProtocol.scala


示例3: write

//设置package包名称以及导入依赖的类
package com.realizationtime.btdogg.persist

import java.time.{Instant, LocalDate}

import com.realizationtime.btdogg.TKey
import com.realizationtime.btdogg.parsing.ParsingResult.{FileEntry, TorrentDir, TorrentFile}
import com.realizationtime.btdogg.persist.MongoPersist.{Liveness, TorrentDocument}
import com.realizationtime.btdogg.persist.MongoTorrentWriter.localDateToString
import reactivemongo.bson.{BSONDateTime, BSONDocument, BSONDocumentWriter, BSONInteger, BSONString, BSONWriter, Macros}

trait MongoTorrentWriter {

  implicit val tkeyWriter = new BSONWriter[TKey, BSONString] {
    override def write(k: TKey): BSONString = BSONString(k.hash)
  }
  implicit val torrentDataFileWriter: BSONDocumentWriter[TorrentFile] = Macros.writer[TorrentFile]
  implicit val torrentDataDirWriter: BSONDocumentWriter[TorrentDir] = Macros.writer[TorrentDir]
  implicit val torrentDataWriter: BSONDocumentWriter[FileEntry] = Macros.writer[FileEntry]
  implicit val instantWriter = new BSONWriter[Instant, BSONDateTime] {
    override def write(t: Instant): BSONDateTime = BSONDateTime(t.toEpochMilli)
  }

  implicit val torrentWriter: BSONDocumentWriter[TorrentDocument] = Macros.writer[TorrentDocument]

  implicit val livenessWriter: BSONDocumentWriter[Liveness] = Macros.writer[Liveness]

  implicit val localDateWriter = new BSONWriter[LocalDate, BSONString] {
    override def write(t: LocalDate): BSONString = BSONString(localDateToString(t))
  }

  implicit val mapWriter: BSONDocumentWriter[Map[LocalDate, Int]] = new BSONDocumentWriter[Map[LocalDate, Int]] {
    def write(map: Map[LocalDate, Int]): BSONDocument = {
      val elements = map.toStream.map { tuple =>
        localDateToString(tuple._1) -> BSONInteger(tuple._2)
      }
      BSONDocument(elements)
    }
  }

}

object MongoTorrentWriter {

  def localDateToString(date: LocalDate): String = date.toString

} 
开发者ID:bwrega,项目名称:btdogg,代码行数:47,代码来源:MongoTorrentWriter.scala


示例4: reactiveMongoApi

//设置package包名称以及导入依赖的类
package repositories

import crypto.CryptoHelpers
import models.EncryptedAuthTokenResponse
import org.joda.time.DateTime
import play.api.Play
import play.api.libs.json.Json
import play.modules.reactivemongo.ReactiveMongoApi
import play.modules.reactivemongo.json.ImplicitBSONHandlers._
import reactivemongo.api.commands.UpdateWriteResult
import reactivemongo.bson.BSONDateTime
import reactivemongo.play.json.collection.JSONCollection

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.ExecutionContext.Implicits.global

trait MonzoRepository {

  def reactiveMongoApi: ReactiveMongoApi

  def collectionFuture: Future[JSONCollection]

  def save(monzoAuth: EncryptedAuthTokenResponse): Future[UpdateWriteResult] = {
    val query = Json.obj("userId" -> monzoAuth.userId)
    val update =
      Json.obj("$setOnInsert" -> Json.obj("clientId" -> monzoAuth.clientId, "userId" -> monzoAuth.userId, "accountId" -> monzoAuth.accountId),
        "$set" -> Json.obj("accessToken" -> monzoAuth.accessToken, "expiresIn" -> monzoAuth.expiresIn, "refreshToken" -> monzoAuth.refreshToken, "tokenType" -> monzoAuth.tokenType, "updated" -> BSONDateTime(new DateTime().getMillis))
    )

    for {
      collection <- collectionFuture
      upsert <- collection.update(query, update, upsert = true)
    } yield upsert
  }

  def findByAccountId(accountId: String)(implicit ec: ExecutionContext) = {
    for {
      collection <- collectionFuture
      result <- collection.find(Json.obj("accountId" -> CryptoHelpers.encrypt(accountId))).one[EncryptedAuthTokenResponse]
    } yield result
  }

}

object MonzoRepository extends MonzoRepository {
  lazy val reactiveMongoApi: ReactiveMongoApi = Play.current.injector.instanceOf[ReactiveMongoApi]
  lazy val collectionFuture: Future[JSONCollection] = reactiveMongoApi.database.map(_.collection[JSONCollection]("monzo"))
} 
开发者ID:adamtrousdale,项目名称:monzo-roundup,代码行数:49,代码来源:MonzoRepository.scala


示例5: AccessToken

//设置package包名称以及导入依赖的类
package models

import reactivemongo.bson.BSONObjectID
import reactivemongo.bson.BSONDateTime
import reactivemongo.bson.Macros
import java.util.Date
import play.api.libs.json.Json
import play.modules.reactivemongo.json.BSONFormats._


case class AccessToken (
    
    val _id: Option[BSONObjectID],
    val accessToken: String, 
    val refreshToken: Option[String], 
    val userId: BSONObjectID, 
    val scope: Option[String], 
    val expiresIn: Int, 
    val createdAt: BSONDateTime, 
    val clientId: String
    
)

object AccessTokenFormatter{
  implicit val accessTokenFormatter = Json.format[AccessToken];
} 
开发者ID:boris9999,项目名称:Play-mongo-oauth2.0,代码行数:27,代码来源:AccessToken.scala


示例6: PublicPostsAccessor

//设置package包名称以及导入依赖的类
package me.lsbengine.api.public

import com.github.nscala_time.time.Imports.DateTime
import me.lsbengine.api.PostsAccessor
import me.lsbengine.database.DatabaseAccessor
import me.lsbengine.database.model.{MongoCollections, Post}
import me.lsbengine.database.model.MongoFormats._
import reactivemongo.api.DefaultDB
import reactivemongo.bson.{BSONDateTime, BSONDocument}

import scala.concurrent.Future

class PublicPostsAccessor(db: DefaultDB)
  extends DatabaseAccessor[Post](db, MongoCollections.postsCollectionName)
    with PostsAccessor {

  def getPost(id: Int): Future[Option[Post]] = {
    val now = DateTime.now
    val query = BSONDocument("id" -> id,
      "published" -> BSONDocument(
        "$lte" -> BSONDateTime(now.getMillis)
      ))
    super.getItem(query)
  }

  def listPosts: Future[List[Post]] = {
    val now = DateTime.now
    val sort = BSONDocument("published" -> -1)
    val query = BSONDocument("published" -> BSONDocument(
      "$lte" -> BSONDateTime(now.getMillis)
    ))
    super.getItems(query = query, sort = sort)
  }
} 
开发者ID:jrabasco,项目名称:LSBEngine,代码行数:35,代码来源:PublicPostsAccessor.scala


示例7: Post

//设置package包名称以及导入依赖的类
package models

import reactivemongo.bson.BSONDateTime
import reactivemongo.play.json._


case class Post(
                 title: String,
                 url: String,
                 announce: String,
                 text: String,
                 created:  BSONDateTime,
                 tags: List[Tag])
case class Tag(
                 name: String,
                 url: String)

object JsonFormats {
  import play.api.libs.json.Json

  implicit val tagFormat = Json.format[Tag]
  implicit val postFormat = Json.format[Post]
} 
开发者ID:desuex,项目名称:lsblog,代码行数:24,代码来源:Post.scala


示例8: read

//设置package包名称以及导入依赖的类
package bson

import java.util.UUID

import org.joda.time.DateTime
import reactivemongo.bson.{BSONDateTime, BSONHandler, BSONString}

package object handlers {
  implicit val UUIDHandler = BSONHandler(
    { read: BSONString => UUID.fromString(read.value) },
    { write: UUID => BSONString(write.toString)  }
  )

  implicit val DateTimeHandler = new BSONHandler[BSONDateTime, DateTime] {
    override def read(bson: BSONDateTime): DateTime = {
      new DateTime(bson.value)
    }

    override def write(t: DateTime): BSONDateTime = {
      BSONDateTime(t.getMillis)
    }
  }
} 
开发者ID:pequalsnp,项目名称:eve-isk-tracker,代码行数:24,代码来源:package.scala



注:本文中的reactivemongo.bson.BSONDateTime类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala DBs类代码示例发布时间:2022-05-23
下一篇:
Scala HashMap类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap