Skip to content

Instantly share code, notes, and snippets.

View nakamura-to's full-sized avatar

Toshihiro Nakamura nakamura-to

View GitHub Profile
@nakamura-to
nakamura-to / AppConfig.java
Last active August 14, 2020 01:27
RedshiftのUNLOADコマンドをDomaで生成する案
package sample;
public class AppConfig implements Config {
@Override
public QueryImplementors getQueryImplementors() {
return new QueryImplementors() {
@Override
public SqlFileSelectQuery createSqlFileSelectQuery(Method method) {
if (method.isAnnotationPresent(Unload.class)) {
@nakamura-to
nakamura-to / sql.md
Last active April 20, 2020 09:49
KotlinのDSLでSQLっぽく書くために

selectするカラムの選択

ラムダで指定できなくはないが、型パラメータが面倒臭いことになる

DSLの利用コード

val query = select({ it.name }, from = ::_Emp) { e -> where { eq(e.id, 1) }}

DSLの定義

val query = select(::_製品移動) { a ->
val b = leftJoin(::_倉庫) { b ->
eq(a.移送元倉庫id, b.倉庫id)
}
val c = leftJoin(::_倉庫) { c ->
eq(a.移送先倉庫id, c.倉庫id)
}
associate(a, b) { 製品移動, 倉庫 ->
製品移動.移送元倉庫 = 倉庫
}
@nakamura-to
nakamura-to / gist:4316660
Created December 17, 2012 08:29
ASP.NET Web API Test in F#
open System
open System.Collections.Generic
open System.Net
open System.Net.Http
open System.Web.Http
open System.Web.Http.Dispatcher
open System.Web.Http.SelfHost
open Microsoft.VisualStudio.TestTools.UnitTesting
open Newtonsoft.Json.Linq
open Newtonsoft.Json.Serialization
@nakamura-to
nakamura-to / sql-annotation.md
Last active January 13, 2019 21:01
Doma 2.22.0にて、SQLをアノテーションに記述するための機能を実験的に追加する

追加するアノテーションは @Sql の1つのみ

  • 前提として@Sql 導入前までのバージョンとの互換性は維持する
  • @Sql のFQNは org.seasar.doma.experimental.Sql

Selectの場合

(これまで通り)SQLをファイルから読む

@Select
Emp select();
@nakamura-to
nakamura-to / gist:2144314
Created March 21, 2012 04:22
Visitor Pattern in JavaScript
// see http://d.hatena.ne.jp/ashigeru/20090113/1231855642
var calc = {
add: function (node) {
return visit(this, node.l) + visit(this, node.r);
},
sub: function (node) {
return visit(this, node.l) - visit(this, node.r);
},
val: function (node) {
@nakamura-to
nakamura-to / FooDao.java
Created November 4, 2017 13:46
可視性がパッケージレベルのDaoを使う
@Dao
public interface FooDao {
public default <R> R findByIds(List<FooId> ids, Collector<Foo, ?, R> collctor) {
FooInteranlDao dao = DaoFactory.get(FooInteranlDao.class);
return Lists.partition(ids, 5000).stream() // partition は List<A> を 第二引数の数ごと区切ってList<List<A>> にする処理です
flatMap(dao::findByIdsInternally)
collect(collctor);
}
}
@nakamura-to
nakamura-to / EmployeeDao.java
Created November 4, 2017 13:21
Doma2でprivateメソッド
@Dao
public interface EmployeeDao {
default List<Employee> selectWithBuilder() {
return selectWithBuilder_private();
}
private List<Employee> selectWithBuilder_private() {
Config config = Config.get(this);
SelectBuilder builder = SelectBuilder.newInstance(config);
@nakamura-to
nakamura-to / Program.fs
Last active July 27, 2017 12:29
F# Computation Expression for ADO.NET TRANsactional Queries
open System.Data.SqlClient
open Tranq
open Tranq.Directive
let insert = required {
let! _ = Database.execute "insert person (id, name) values (1, 'hoge1')"
let! _ = Database.execute "insert person (id, name) values (2, 'hoge2')"
let! _ = Database.execute "insert person (id, name) values (3, 'hoge3')"
return () }
@nakamura-to
nakamura-to / gist:1861338
Created February 18, 2012 23:48
Function.prototype.apply and Function.prototype.call
function f(a, b, c) {
console.log(this);
console.log(a);
console.log(b);
console.log(c);
}
var context = {
name: 'context'
};