Skip to content

Commit c180057

Browse files
committed
read/write buffers
1 parent 1e32a86 commit c180057

File tree

7 files changed

+36
-13
lines changed

7 files changed

+36
-13
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var rowBase = function() {
1313
function fieldsForObject(obj) {
1414
return Object.keys(obj).filter(function (key) {
1515
var value = obj[key];
16-
return value instanceof Date || value !== null && value !== undefined && !(value instanceof Object);
16+
return value instanceof Date || value instanceof Buffer || value !== null && value !== undefined && !(value instanceof Object);
1717
});
1818
}
1919

@@ -23,7 +23,7 @@ var rowBase = function() {
2323
return false;
2424
} else {
2525
var value = obj[key];
26-
return !(value instanceof Date) && value instanceof Object;
26+
return !(value instanceof Date) && !(value instanceof Buffer) && value instanceof Object;
2727
}
2828
});
2929
}

test/describeDatabase.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,30 @@ module.exports = function(name, config, database, otherTests) {
112112
return expect(database.clean(people)).to.eql([{
113113
id: p.id,
114114
name: "bob",
115-
address_id: null
115+
address_id: null,
116+
photo: null
116117
}]);
117118
});
118119
});
119120
});
120121

122+
describe('binary', function () {
123+
it('can store binary', function () {
124+
var photo = new Buffer('♥︎');
125+
126+
var bob = person({
127+
name: 'bob',
128+
photo: photo
129+
});
130+
131+
return bob.save().then(function () {
132+
return db.query('select * from people').then(function (people) {
133+
expect(people[0].photo.toString()).to.equal(photo.toString());
134+
});
135+
});
136+
});
137+
});
138+
121139
it("can insert without connecting", function() {
122140
var db = sworm.db(config);
123141
var person = db.model({
@@ -133,7 +151,8 @@ module.exports = function(name, config, database, otherTests) {
133151
return expect(database.clean(people)).to.eql([{
134152
id: p.id,
135153
name: "bob",
136-
address_id: null
154+
address_id: null,
155+
photo: null
137156
}]);
138157
});
139158
});
@@ -204,7 +223,8 @@ module.exports = function(name, config, database, otherTests) {
204223
expect(database.clean(people)).to.eql([{
205224
id: p.id,
206225
name: "bob's name is 'matilda'",
207-
address_id: null
226+
address_id: null,
227+
photo: null
208228
}]);
209229
});
210230
});
@@ -294,7 +314,8 @@ module.exports = function(name, config, database, otherTests) {
294314
expect(database.clean(people)).to.eql([{
295315
id: p.id,
296316
name: "jane",
297-
address_id: null
317+
address_id: null,
318+
photo: null
298319
}]);
299320
});
300321
});
@@ -671,7 +692,8 @@ module.exports = function(name, config, database, otherTests) {
671692
expect(database.clean(people)).to.eql([{
672693
id: bob.id,
673694
name: 'bob',
674-
address_id: null
695+
address_id: null,
696+
photo: null
675697
}]);
676698
});
677699
});

test/mssqlSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var database = {
1010
}
1111

1212
return createTable("people",
13-
'CREATE TABLE [dbo].[people]([id] [int] IDENTITY(1,1) NOT NULL, [name] [nvarchar](50) NOT NULL, [address_id] [int] NULL)'
13+
'CREATE TABLE [dbo].[people]([id] [int] IDENTITY(1,1) NOT NULL, [name] [nvarchar](50) NOT NULL, [address_id] [int] NULL, photo varbinary(10) null)'
1414
).then(function() {
1515
return createTable("people_addresses",
1616
'CREATE TABLE [dbo].[people_addresses]([address_id] [int] NOT NULL, [person_id] [int] NOT NULL, [rating] [int] NULL)'

test/mysqlSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var database = {
2424
}
2525

2626
return createTable("people",
27-
'create table if not exists people (id serial NOT NULL, name varchar(50) NOT NULL, address_id int NULL)'
27+
'create table if not exists people (id serial NOT NULL, name varchar(50) NOT NULL, address_id int NULL, photo varbinary(10) null)'
2828
).then(function() {
2929
return createTable("people_addresses",
3030
'create table if not exists people_addresses(address_id int NOT NULL, person_id int NOT NULL, rating int NULL)'

test/oracleSpec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (!process.env.TRAVIS) {
5151
}
5252

5353
return createTable("people", "id",
54-
'create table people (id number primary key, name varchar2(50) NOT NULL, address_id number NULL)'
54+
'create table people (id number primary key, name varchar2(50) NOT NULL, address_id number NULL, photo raw(10) null)'
5555
).then(function() {
5656
return createTable("people_addresses", "address_id",
5757
'create table people_addresses(address_id int NOT NULL, person_id int NOT NULL, rating int NULL)',
@@ -191,7 +191,8 @@ if (!process.env.TRAVIS) {
191191
expect(rows.metaData).to.eql([
192192
{name: 'ID'},
193193
{name: 'NAME'},
194-
{name: 'ADDRESS_ID'}
194+
{name: 'ADDRESS_ID'},
195+
{name: 'PHOTO'}
195196
]);
196197
});
197198
});

test/postgresSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var database = {
6262
}
6363

6464
return createTable("people",
65-
'create table if not exists people (id serial NOT NULL, name varchar(50) NOT NULL, address_id int NULL)'
65+
'create table if not exists people (id serial NOT NULL, name varchar(50) NOT NULL, address_id int NULL, photo bytea null)'
6666
).then(function () {
6767
return createTable("people_addresses",
6868
'create table if not exists people_addresses(address_id int NOT NULL, person_id int NOT NULL, rating int NULL)'

test/sqliteSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var database = {
1010
}
1111

1212
return createTable("people",
13-
'create table if not exists people (id integer primary key, name varchar(50) NOT NULL, address_id integer NULL)'
13+
'create table if not exists people (id integer primary key, name varchar(50) NOT NULL, address_id integer NULL, photo blob null)'
1414
).then(function() {
1515
return createTable("people_addresses",
1616
'create table if not exists people_addresses(address_id integer NOT NULL, person_id integer NOT NULL, rating integer NULL)'

0 commit comments

Comments
 (0)